This question already has answers here:
firebaserecycleradapter() cannot be applied to FirebaseRecyclerAdapter
(5个答案)
在10个月前关闭。
同样的错误不断出现。我猜他们现在改变了它的工作方式,但是由于我是菜鸟,所以我真的需要帮助修复它。
“((Category.class,R.layout.menu_item,MenuViewHolder.class,category)”)这行是红色的,它指出FirebaseRecyclerAdapter中的FirebaseRecyclerAdapter()无法应用于(此处是一堆代码)。
接下来创建
您可以在这里找到更多信息:
https://github.com/firebase/FirebaseUI-Android/blob/master/database/README.md#firebaseui-for-realtime-database
(5个答案)
在10个月前关闭。
同样的错误不断出现。我猜他们现在改变了它的工作方式,但是由于我是菜鸟,所以我真的需要帮助修复它。
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,category)”)这行是红色的,它指出FirebaseRecyclerAdapter中的FirebaseRecyclerAdapter()无法应用于(此处是一堆代码)。
最佳答案
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
// ...
}
};
您可以在这里找到更多信息:
https://github.com/firebase/FirebaseUI-Android/blob/master/database/README.md#firebaseui-for-realtime-database
09-13 11:41