I have a cursor which retrieves a list of ingredients and populates an adapter, which is then assigned to a recycler View having checkboxes. The problem I\'ve got is that, w
RecyclerView removes (recycles) the unseen views from the layout on scrolling, this is the basic behavior of recyclerView in order to reduce memory use.
When a view with a checkbox is recycled, a checked checkbox gets unchecked and if it has a listener, the listener gets called.
You can remove the listener from the view when it is recycled. Just override the onViewRecycled method.
@Override
public void onViewRecycled(@NonNull MyViewHolder holder) {
holder.checkBox.setOnCheckedChangeListener(null);
super.onViewRecycled(holder);
}
When the view is constructed again, while scrolling, your listener will also be added again.