I've implemented a recycler view with an adapter and everything. I can reverse the list of items with
Collections.reverse(items);
and then run through the list to notify the adapter of this change
final int end = items.size() - 1;
for (int i = 0; i < end; i++) {
mAdapter.notifyItemMoved(0, end - i);
}
So far so good. What I want to do now is to swap two items in that list and animate this change.
Collections.swap(items, 5, 8);
mAdapter.notifyItemMoved(5, 8);
mAdapter.notifyItemMoved(8, 5);
The problem is, this is not being animated and I couldn't find out why.
I do want something similar to the simple reverse animation.
Any ideas?
Soon after I wrote this I hacked a little more and found the reason. Turns out, my problem does relate to the following thread:
No animation on item removal on RecyclerView
I did mess up my notifyDataSetChanged() and notifyItemMoved(0, 1) calls. Once notifyDataSetChanged() is called, the items are swapped without an animation and notifyItemMoved has no effect.
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