我尝试使用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"
}
}
答案 0 :(得分:0)
在您的数据库中,您有Name
,Date
,Image
,您需要在数据库中将它们更改为小写,使其变为name
,{{1 }和date
。
然后使用以下POJO类:
image