Я новичок в Android. У меня проблемы с добавлением текстовых представлений на карточке в список с помощью адаптера. Я следовал учебнику на YouTube, но он не работает для меня. Кроме того, я посмотрел другие подобные вопросы, но так как я новичок, я не в состоянии понять решения. Я был бы признателен, если бы кто-нибудь помог мне с этим.
Это моя карта с макетом просмотра текста, которая называется job_row
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="3dp"
android:elevation="90dp"
android:layout_margin="15dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="112dp"
android:background="#fff"
android:orientation="vertical">
<ImageView
android:id="@+id/prof_pic"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:scaleType="centerCrop"
android:src="@drawable/prof_pic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/profName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:fontFamily="sans-serif"
android:text="Poster Name"
android:textColor="#000"
android:textSize="16sp"
android:textStyle="normal"
app:layout_constraintStart_toEndOf="@+id/prof_pic"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/jobName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif-black"
android:text="Job Name"
android:textColor="#000"
android:textSize="16sp"
app:layout_constraintStart_toEndOf="@+id/prof_pic"
app:layout_constraintTop_toBottomOf="@+id/profName" />
<TextView
android:id="@+id/jobLocation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif-light"
android:text="Job Location"
android:textColor="#000"
android:textSize="14sp"
app:layout_constraintStart_toEndOf="@+id/prof_pic"
app:layout_constraintTop_toBottomOf="@+id/jobName" />
<TextView
android:id="@+id/jobCharge"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:fontFamily="sans-serif-light"
android:text="Job Charge"
android:textColor="#000"
android:textSize="14sp"
app:layout_constraintBaseline_toBaselineOf="@+id/jobLocation"
app:layout_constraintStart_toEndOf="@+id/jobLocation" />
</androidx.constraintlayout.widget.ConstraintLayout>
домашняя страница макет, где я хочу, чтобы мое отображение карты отображалось
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Home"
>
<SearchView
android:id="@+id/search"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="80dp"
android:background="#fff"
android:iconifiedByDefault="false"
android:queryBackground="@android:color/transparent"
android:queryHint="Search Jobs"
android:textColor="#fff"
android:textSize="10dp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/newBtn"
style="@style/TextButton"
android:layout_width="30dp"
android:layout_height="27dp"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:text="New"
android:textAlignment="viewStart"
android:textSize="14sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/search" />
<Button
android:id="@+id/nearYouBtn"
style="@style/TextButton"
android:layout_width="70dp"
android:layout_height="30dp"
android:layout_marginStart="70dp"
android:layout_marginTop="24dp"
android:text="Near You"
android:textAlignment="viewStart"
android:textSize="14sp"
app:layout_constraintStart_toEndOf="@+id/newBtn"
app:layout_constraintTop_toBottomOf="@+id/search" />
<Button
android:id="@+id/recommendBtn"
style="@style/TextButton"
android:layout_width="96dp"
android:layout_height="25dp"
android:layout_marginStart="70dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:text="Recommended"
android:textAlignment="viewStart"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/nearYouBtn"
app:layout_constraintTop_toBottomOf="@+id/search" />
<ListView
android:id="@+id/newjob_list"
android:layout_width="329dp"
android:layout_height="446dp"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="16dp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/nearYouBtn" />
Домашний класс
package com.example.oddsynew;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.firebase.ui.database.FirebaseListAdapter;
import com.firebase.ui.database.FirebaseListOptions;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class Home extends AppCompatActivity {
ListView lv;
FirebaseListAdapter adapter;
DatabaseReference myRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
lv = (ListView) findViewById(R.id.newjob_list);
myRef = FirebaseDatabase.getInstance().getReference().child("Job");
FirebaseListOptions<Job> options = new FirebaseListOptions.Builder<Job>()
.setLayout(R.layout.job_row)
.setQuery(myRef, Job.class)
.build();
adapter = new FirebaseListAdapter(options) {
@Override
protected void populateView(View v, Object model, int position) {
TextView recruiterName = v.findViewById(R.id.profName);
TextView jobName = v.findViewById(R.id.jobName);
TextView jobLocation = v.findViewById(R.id.jobLocation);
TextView jobCharge = v.findViewById(R.id.jobCharge);
Job job = (Job) model;
recruiterName.setText(job.getPoster_name());
jobName.setText(job.getJob_name());
jobLocation.setText(job.getLocation());
jobCharge.setText(job.getJob_charge().toString());
}
};
lv.setAdapter(adapter);
}
@Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}
}
И мой адаптер класса
package com.example.oddsynew;
public class Job {
private String job_name;
private String poster_name;
private String location;
private Double job_charge;
public String getJob_name() {
return job_name;
}
public Job(String job_name, String poster_name, String location, Double job_charge) {
this.job_name = job_name;
this.poster_name = poster_name;
this.location = location;
this.job_charge = job_charge;
}
public void setJob_name(String job_name) {
this.job_name = job_name;
}
public String getPoster_name() {
return poster_name;
}
public void setPoster_name(String poster_name) {
this.poster_name = poster_name;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public Double getJob_charge() {
return job_charge;
}
public void setJob_charge(Double job_charge) {
this.job_charge = job_charge;
}
}