FirebaseRecyclerAdapter无法应用

时间:2019-04-15 06:11:15

标签: android android-recyclerview

enter image description here

private void loadMenu() {
        FirebaseRecyclerOptions<Category> options=new FirebaseRecyclerOptions.Builder<Category>().setQuery(category,Category.class).build();
        FirebaseRecyclerAdapter<Category, MenuViewHolder> adapter=new FirebaseRecyclerAdapter<Category, MenuViewHolder>(Category.class,R.layout.menu_item,MenuViewHolder.class,category) {
            @NonNull
            @Override
            public MenuViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
                return null;
            }

            @Override
            protected void onBindViewHolder(MenuViewHolder viewHolder, int position, Category model) {
                viewHolder.txtMenuName.setText(model.getName());
                Picasso.with(getBaseContext()).load(model.getImage())
                        .into(viewHolder.imageView);
                final Category clickItem=model;
                viewHolder.setItemClickListener(new ItemClickListener() {
                    @Override
                    public void onClick(View view, int position, boolean isLongClick) {
                        Toast.makeText(Home.this, ""+clickItem.getName(), Toast.LENGTH_SHORT).show();

                    }


                });
            }
        };
        recycler_menu.setAdapter(adapter);
    }

1 个答案:

答案 0 :(得分:0)

由于错误,您给出了错误的参数。由于您已经在使用FirebaseRecyclerOptions

  FirebaseRecyclerOptions<Category> options =
            new FirebaseRecyclerOptions.Builder<Category>()
                    .setQuery(MenuViewHolder, Category.class)
                    .build();

所以只需将该行更改为此

FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder>(options) {