相同的错误不断出现。我猜他们现在改变了它的工作方式,但是由于我是菜鸟,所以我真的需要帮助修复它。
private void loadMenu() {
adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder>
(Category.class, R.layout.menu_item, MenuViewHolder.class, category) {
@NonNull
@Override
public MenuViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return null;
}
@Override
protected void onBindViewHolder(@NonNull MenuViewHolder viewHolder, int position, @NonNull Category model) {
viewHolder.txtMenuName.setText(model.getNama());
Picasso.get().load(model.getImage()).into(viewHolder.imageView);
final Category clickItem = model;
viewHolder.setItemClickListener(new ItemClickListener() {
@Override
public void onClick(View view, int position, boolean isLongClick) {
//get Category Id and Send to new Activity
Intent foodlist = new Intent(Home.this, FoodList.class);
foodlist.putExtra("CategoryId",adapter.getRef(position).getKey());
startActivity(foodlist);
}
});
}
“(Category.class,R.layout.menu_item,MenuViewHolder.class,类别)”这行是红色的,它指出FirebaseRecyclerAdapter中的FirebaseRecyclerAdapter()无法应用于(此处是一堆代码)。
答案 0 :(得分:1)
FirebaseRecyclerAdapter
将Query
绑定到RecyclerView。添加,删除或更改数据后,这些更新将自动实时地实时应用到您的UI。
首先,通过构建FirebaseRecyclerOptions
配置适配器:
FirebaseRecyclerOptions<Category> options =
new FirebaseRecyclerOptions.Builder<Category>()
.setQuery(category, Category.class)
.build();
接下来创建FirebaseRecyclerAdapter
对象。您应该已经有一个ViewHolder子类来显示每个项目。
FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder>(options) {
@Override
public ChatHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// Create a new instance of the ViewHolder, in this case we are using a custom
// layout called R.layout.menu_item for each item
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.menu_item, parent, false);
return new MenuViewHolder(view);
}
@Override
protected void onBindViewHolder(MenuViewHolder holder, int position, Category model) {
// Bind the Chat object to the ChatHolder
// ...
}
};
您可以在此处找到更多信息: