onItemClick 返回不同的值

onItemClick is returning different values

我的适配器中有这个 ViewHolder。

public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        ImageView optionImage;
        ImageView optionAddFavorites;
        BMLTextView optionText;
        RelativeLayout lay_icon;

        ViewHolder(View itemView) {
            super(itemView);
            optionImage = (ImageView) itemView.findViewById(R.id.img_option);
            optionAddFavorites = (ImageView) itemView.findViewById(R.id.iv_add_favorites);
            optionText = (BMLTextView) itemView.findViewById(R.id.txt_option_description);
            lay_icon = (RelativeLayout) itemView.findViewById(R.id.lay_icon);

            itemView.setOnClickListener(this);

            this.setIsRecyclable(false);
        }

        @Override
        public void onClick(View view) {
            if (mClickListener != null) mClickListener.onItemClick(view, getAdapterPosition());
        }
    }

稍后,在我的 Activity 中,我实现了:

public class OperateOptionSectionItemHelperImpl
        implements OperateOptionRVAdapter.ItemClickListener, OperateOptionSectionItemHelper {

我已经覆盖了 onItemClick 方法,如下所示:

@Override
    public void onItemClick(View view, int position) {
    if (isEditingFavorites) {

        switch (view.getId()) {

            case R.id.iv_add_favorites:
                Log.e("onItemClick", "Add to favorites iv_add_favorites: " + R.id.iv_add_favorites + " parent: " + view.getId());

                break;
            case R.id.img_option:
                Log.e("onItemClick", "Add to favorites img_option: " + R.id.img_option + " parent: " + view.getId());

                break;

            default:
                Log.e("onItemClick", "Default");

        }

    } else {
        Log.e("onItemClick", "Rest of the view");

        }
    }
}

我没有得到点击视图的 ID...我做错了什么?

那是因为您将 ClickListener 设置为 itemView。在面对你应该设置 ClickListener 到 optionImage 和 optionAddFavorites 改变

itemView.setOnClickListener(this);

optionImage.setOnClickListener(this);
optionAddFavorites.setOnClickListener(this);