如何使用RecyclerView在Firebase数据库的子(商店)下添加子(产品)
1。错误
找不到适合的构造函数 FirebaseRecyclerAdapter(Class,int,Class,Query) 建设者 FirebaseRecyclerAdapter.FirebaseRecyclerAdapter(Class,int,Class,FirebaseArray) 不适用(参数不匹配;类别不能为 转换为Class)构造函数 FirebaseRecyclerAdapter.FirebaseRecyclerAdapter(Class,int,Class,Query) 不适用(参数不匹配;类别不能为 转换为Class)
2。我使用的代码
RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;
FirebaseDatabase database;
DatabaseReference productList;
String foodtarastoreId;
FirebaseRecyclerAdapter<FooProduct, FooProductViewHolder> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_food_product);
//Firebase
database = FirebaseDatabase.getInstance();
productList = database.getReference("Product");
recyclerView = (RecyclerView) findViewById(R.id.recycler_fproduct_list);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
if(getIntent() != null)
foodtarastoreId = getIntent().getStringExtra("foodtarastoreId");
if (!foodtarastoreId.isEmpty() && foodtarastoreId != null)
{
loadListProduct(foodtarastoreId);
}
}
private void loadListProduct(String foodtarastoreId) {
adapter = new FirebaseRecyclerAdapter<FooProduct, FooProductViewHolder>(FoodProduct.class, R.layout.fproduct_item,
FooProductViewHolder.class,
productList.orderByChild("menuid").equalTo(foodtarastoreId)) {
protected void populateViewHolder(FooProductViewHolder viewHolder, FooProduct model, int position) {
}
};
3。 VIEWHOLDER
public TextView fooProductName;
public ImageView fooProductImage;
private ItemClickListener itemClickListener;
public void setItemClickListener(ItemClickListener itemClickListener) {
this.itemClickListener = itemClickListener;
}
public FooProductViewHolder(@NonNull View itemView) {
super(itemView);
fooProductName = (TextView)itemView.findViewById(R.id.foodproduct_name);
fooProductImage = (ImageView)itemView.findViewById(R.id.foodproduct_image);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
itemClickListener.onClick(v, getAdapterPosition(), false);
}
}
4。 Firebase数据库中的产品
private String name, image, description, price, discount, menuid;
public FooProduct() {
}
public FooProduct(String name, String image, String description, String price, String discount, String menuid) {
this.name = name;
this.image = image;
this.description = description;
this.price = price;
this.discount = discount;
this.menuid = menuid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getDiscount() {
return discount;
}
public void setDiscount(String discount) {
this.discount = discount;
}
public String getMenuid() {
return menuid;
}
public void setMenuid(String menuid) {
this.menuid = menuid;
}
}