Android RecyclerView : notifyDataSetChanged() IllegalStateException

前端 未结 22 1862
天涯浪人
天涯浪人 2020-11-28 02:57

I\'m trying to update the items of a recycleview using notifyDataSetChanged().

This is my onBindViewHolder() method in the recycleview adapter.

@Over         


        
22条回答
  •  臣服心动
    2020-11-28 03:33

    This is happening because you're probably setting the 'listener' before you configure the value for that row, which makes the listener to get triggered when you 'configure the value' for the checkbox.

    What you need to do is:

    @Override
    public void onBindViewHolder(YourAdapter.ViewHolder viewHolder, int position) {
       viewHolder.mCheckBox.setOnCheckedChangeListener(null);
       viewHolder.mCheckBox.setChecked(trueOrFalse);
       viewHolder.setOnCheckedChangeListener(yourCheckedChangeListener);
    }
    

提交回复
热议问题