[英]Recycler view is not displaying data from firebase using an array list
我正在使用数组列表从 firebase 数据库中检索数据,然后填充回收器我的 firebase视图。 数据未显示在回收站视图中。
我的 Model class 在这里
public class ModelCategory {
String id,category,uid;
long timestamp;
public ModelCategory() {
}
public ModelCategory(String id, String category, String uid, long timestamp) {
this.id=id;
this.category =category;
this.uid=uid;
this.timestamp=timestamp;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
Class 用于加载回收器视图
private void loadCategories() {
categoryArrayList= new ArrayList<>();
DatabaseReference reference=FirebaseDatabase.getInstance().getReference("category");
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
categoryArrayList.clear();
for(DataSnapshot ds: snapshot.getChildren()){
ModelCategory category = ds.getValue(ModelCategory.class);
categoryArrayList.add(category);
}
adapterCategory= new AdapterCategory(DashboardAdminActivity.this,categoryArrayList);
binding.categoriesRvk.setAdapter(adapterCategory);
}
加载类别方法在主活动中。
我的适配器
public void onBindViewHolder(@NonNull HolderCategory holder, int position) {
//get data
ModelCategory model= categoryArrayList.get(position);
String id= model.getId();
String uid= model.getUid();
String category= model.getCategory();
long timestamp= model.getTimestamp();
//set data
holder.categoryTv.setText(category);
//handle delete btn click
holder.deleteBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "deleted "+category, Toast.LENGTH_SHORT).show();
}
});
这是我正在使用的适配器
正如我在您的屏幕截图中看到的那样,它是categories
而不是category
。 所以请更改:
DatabaseReference reference=FirebaseDatabase.getInstance().getReference("category");
进入:
DatabaseReference reference=FirebaseDatabase.getInstance().getReference("categories");
👆
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.