[英]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.