解决RecyclerView复用,导致Item混乱问题,checkbox也类似此做法

一、在onBindViewHolder方法中给要操作的控件setTag

holderTwo.item_ll_root.setTag(position);

二、在onBindViewHolder方法中,记录该控件的状态

// 显示隐藏词义
    holderTwo.item_ll_root.setOnClickListener(new View.OnClickListener()

    {
        @Override public void onClick (View v)
        { // item显示词义复用问题  
            if (!mClickList.contains(holderTwo.item_ll_root.getTag())) {
                mClickList.add(position);
                holderTwo.item_word_mean.setVisibility(View.VISIBLE);
            } else {
                for (int i = 0; i < mClickList.size(); i++) {
                    if (mClickList.get(i) == holderTwo.item_ll_root.getTag()) {
                        mClickList.remove(i);
                        holderTwo.item_word_mean.setVisibility(View.GONE);
                    }
                }
            }
        }
    }
三、在onBindViewHolder方法最后根据集合记录的控件状态,控制其状态
//解决item显示词义复用问题
if (mClickList.contains(position)) {
    holderTwo.item_word_mean.setVisibility(View.VISIBLE);
} else {
    holderTwo.item_word_mean.setVisibility(View.GONE);
}

 

你可能感兴趣的:(解决RecyclerView复用,导致Item混乱问题,checkbox也类似此做法)