简体   繁体   English

当我单击里面的图像视图时,如何摆脱recyclerview的单击?

[英]How can I get rid of recyclerview item's click when I click on an imageview inside it?

Currently I set Imageview click even in ViewHolder class like this: 目前,我甚至在ViewHolder类中将Imageview设置为click,如下所示:

public class HomeMenuViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener, View.OnClickListener {

        public ImageView imageView;
        String[] tagBackgroundColors;
        String[] tagBorderColors;

        public HomeMenuViewHolder(View itemView, int viewType) {
            super(itemView);
            this.viewType = viewType;

            imageView = (ImageView) itemView.findViewById(R.id.img_menu);
            imageView.setOnClickListener(this);

        }

        @Override
        public void onClick(View v) {
            clickListener.onClick(getAdapterPosition(), false);
            int id = v.getId();
            if (id == R.id.cb_share_dday_show) {
                CheckBox checkBox = (CheckBox) v;
                if (checkBox.isChecked()) {
                    mPref.setShareDdayShow(Cons.TRUE);
                } else {
                    mPref.setShareDdayShow(Cons.FALSE);
                }
                menuCallback.refreshFragments();
            } else if (id == R.id.img_menu) {
                showChangeColorDialog();
            }
        }


    private void showChangeColorDialog() {
            Dialog gridViewDialog = new Dialog(mContext);
            gridViewDialog.setContentView(R.layout.dialog_change_color);
            // You have to create the GridView object with gridViewDialog
            GridView gv = ((GridView) gridViewDialog.findViewById(R.id.grid_change_color));
            ChangeTagIconAdapter adapter = new ChangeTagIconAdapter(mContext, tagBackgroundColors, tagBorderColors);
            gv.setAdapter(adapter);
            gridViewDialog.show();

        }
}

I put the recyclerview inside a navigation drawer, the function of recyclerview's item is closing the drawer. 我将recyclerview放在导航抽屉中,recyclerview的项目功能是关闭抽屉。 What I want is when I click on the imageview inside recyclerview's items, a dialog should appear without closing the drawer but I always get click even of both recyclerview's item and the imageview inside it. 我想要的是,当我单击recyclerview的项目内的imageview时,应该出现一个对话框而不关闭抽屉,但即使单击recyclerview的项目和其中的imageview,我也总是会单击。 Please tell me how to fix it. 请告诉我如何解决。 Thank you! 谢谢!

I figured it out. 我想到了。 I should set click listener in adapter instead of in viewholder. 我应该在适配器中而不是在viewholder中设置click listener。 Now it works ;) 现在可以了;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在recyclelerview中点击当前项目的按钮时,如何显示上一个项目的按钮? - How can I make previous item's button visible when click on current item's button in recyclerview? 当我使用 ViewPager2 在 tabLayout 中单击 recyclerView 项目时创建 Imageview - Create Imageview when I click recyclerView item in tabLayout with ViewPager2 当我单击被推送到Firebase的recyclerview项目时,如何获取Firebase子键值 - How can i get firebase child key value when i click on recyclerview item which is pushed to firebase 当我单击RecyclerView项时,我想获取ID - I want to get the id when I click a RecyclerView item 当我单击图像按钮时,获取recyclerview项目的位置 - get the position of a recyclerview item when I click on an imagebutton 如何在另一个RecyclerView的项目中实现RecyclerView - How can I implement a RecyclerView inside another RecyclerView's item 如何在另一个 recyclerview 的项目中创建 RecyclerView? - How can i create a RecyclerView inside of the another recyclerview's item? 当我单击 recyclerView 中的项目时,另一个项目将单击 - when I click item in my recyclerView, another item will click 单击按钮时如何滑动RecyclerView项目..? - How to swipe RecyclerView Item when I click Button..? 如何解决单击水平 RecyclerView 中的项目的问题? - How can I solve a problem with click on item in horizontal RecyclerView?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM