setItemClickListener不起作用

时间:2018-07-15 19:59:17

标签: android onclicklistener onitemclicklistener

我目前正在关注在android studio上进行开发的教程,但我遇到了一个问题:当我单击自己的项目时,我想了解另一种意图,但它没有用,我无法弄清楚。 这是我的代码

private void loadMenu(){
     adapter = new FirebaseRecyclerAdapter<Category,MenuViewHolder>(Category.class,R.layout.menu_item, MenuViewHolder.class, category) {
        @Override
        protected void populateViewHolder(final MenuViewHolder viewHolder, Category model, int position) {
            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();
                    Intent foodList = new Intent(Home.this, FoodList.class);
                    foodList.putExtra("CategoryId", adapter.getRef(position).getKey());
                    startActivity(foodList);

                }
            });
        }
    };

    recycler_menu.setAdapter(adapter);
}

如果你们能帮助我,那真的很酷。 非常感谢

0 个答案:

没有答案