Reputation: 165
I have a RecyclerView
and I would like to allow users to select views using a long press. This works fine except that the ripple effect is terminated as soon as I call either notifyItemChanged()
or notifyDataSetChanged
in order to indicate the selection. How can I prevent this from happening?
Note, this question has been asked before (Example 1, Example 2). The answer to those questions has been to use notifyItemChanged
instead of notifyDataSetChanged
. I have tried both of these and it does not change the behavior for me.
Upvotes: 4
Views: 710
Reputation: 1543
a) add DiffUtilCallback to your adapter
b) make sure what your areItemsTheSame
method compare items by id and not by content.
Because if it compare by content, it thinks what you remove previous cell and insert new, and kill ripple effect.
Upvotes: 0
Reputation: 164
There are two versions of notifyItemChanged() method. One takes only position and the other one takes position and a payload.
And in my case the first one broke the ripple effect, while the second one worked. At least when I passed the object that just has been changed as the payload.
Upvotes: 2