I have a RecyclerView Adapter backed by a SortedList. If I make a change to an item, it both changes the item and repositions it in the list.
I've found that if I use notifyItemChanged
on either the item's starting or ending position, it does not seem to have any effect even in conjunction with notifyItemMoved
, either before or after.
If I use notifyItemMoved
, it correctly triggers the movement animation, but the view does not change and still displays the outdated information.
If I use notifyDatasetChanged
it updates the row and then moves it, but it does so sequentially which is slow, and it obviously notifies the entire list which is not exactly desirable.
Is there any way I can combine the moving and updating animations? And why doesn't notifyItemChanged
do anything?
In RecyclerView.Adapter reference is said, that notifyItemMoved()
is just structural change and therefore won't update data. On the other hand notifyItemChanged()
is said to be data change.
When calling notifyItemChanged()
, it will call RecyclerView#onBindViewHolder()
, so it should update your view.
Working approach for me for updating and moving is:
notifyItemChanged(oldPos); notifyItemMoved(oldPos, newPos);
You can use:
SortedList.updateItemAt(int position, Objet newItem)
The newItem
is the updated item, and position
is the current position. This method replaces the current item for newItem
and repositions it on the list (and the recyclerview link to it).
Here is the official documentation.
I hope this helps you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With