gpt4 book ai didi

java - Firebase Recycler 适配器不显示数据,但加载图像

转载 作者:行者123 更新时间:2023-11-29 02:32:08 24 4
gpt4 key购买 nike

我正在尝试使用 Firebase 编写适配器代码。问题:RecyclerView 只加载图像,但其他信息为空。我不知道是什么问题,因为 Android Studio 没有显示任何错误。只有这样的东西,但是是蓝色的:

W/ClassMapper: No setter/field for Date found on class com.boiko.taisiia.praca.Model.Dates
W/ClassMapper: No setter/field for Name found on class com.boiko.taisiia.praca.Model.Dates

这是我的 POJO 类:

public class Dates {
private String DataName, Data, Image;
public Dates(){};
public Dates(String dataName,String data, String image){
DataName = dataName;
Data = data;
Image = image;
}

public String getDataName() {
return DataName;
}

public void setDataName(String dataName) {
DataName = dataName;
}

public String getData() {
return Data;
}

public void setData(String data) {
Data = data;
}

public String getImage() {
return Image;
}

public void setImage(String image) {
Image = image;
}
}

这是 ViewHolder:

public class DatesViewHolder extends RecyclerView.ViewHolder{
public ImageView data_img;
public TextView data_name;
public TextView data;


public DatesViewHolder(View itemView) {
super(itemView);
data_img = (ImageView)itemView.findViewById(R.id.date_img);
data_name = (TextView) itemView.findViewById(R.id.date_name);
data = (TextView) itemView.findViewById(R.id.date);
}
}

适配器:

public class DatesList extends AppCompatActivity {
RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;

FirebaseDatabase database;
DatabaseReference dataList;


FirebaseRecyclerAdapter<Dates, DatesViewHolder> adapter;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dates_list);

//Firebase implementation
database = FirebaseDatabase.getInstance();
dataList = database.getReference().child("Dates");

recyclerView = (RecyclerView)findViewById(R.id.recycler_dates);
recyclerView.setHasFixedSize(true);

layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
loadListDates();
}

private void loadListDates() {
adapter = new FirebaseRecyclerAdapter<Dates, DatesViewHolder>(Dates.class, R.layout.date_item, DatesViewHolder.class, dataList) {
@Override
protected void populateViewHolder(DatesViewHolder viewHolder, Dates dataList, int i) {
viewHolder.data_name.setText(dataList.getDataName());
viewHolder.data.setText(dataList.getData());
Picasso.with(getBaseContext()).load(dataList.getImage())
.into(viewHolder.data_img);

}
};
recyclerView.setAdapter(adapter);
}
}

数据库:

    "Dates":{

"01":{
"Name": "Magicians",
"Date": "1.02.2018",
"Image": "http://ex-fs.net/uploads/posts/2017-01/1485425221_0503512.jpg"
},
"02":{
"Name": "Grimm",
"Date": "3.03.2018",
"Image": "http://ex-fs.net/uploads/posts/2015-10/1446316149_grimm.jpg"
},
"03":{
"Name": "Stranger Things",
"Date": "25.04.2018",
"Image": "http://ex-fs.net/uploads/posts/2017-01/1483352456_homeland.jpg"
}

}

最佳答案

在你的数据库中你有Name, Date, Image,你需要在数据库中将它们改成小写才能变成这样姓名日期图片

然后使用下面的 POJO 类:

public class Dates {
private String date, name, image;
public Dates(){};
public Dates(String date,String name, String image){
this.name=name;
this.date=date;
this.image=image;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name=name;
}

public String getDate() {
return date;
}

public void setDate(String date) {
this.date=date;
}

public String getImage() {
return Image;
}

public void setImage(String image) {
this.image=image;
}
}

关于java - Firebase Recycler 适配器不显示数据,但加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49099890/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com