FirebaseRecyclerAdapter 中的 FirebaseRecyclerAdapter() 无法应用于



同样的错误不断出现。我猜他们现在改变了它的工作方式,但由于我是菜鸟,我真的需要帮助修复它。

    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(( 不能应用于(这里有一堆代码(。

FirebaseRecyclerAdapterQuery绑定到回收器视图。添加、删除或更改数据时,这些更新会自动实时应用于您的 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

相关内容

  • 没有找到相关文章

最新更新