I have Activity1 with a fragment which has a RecyclerView in it. Selecting an item on the list starts Activity2 which modifies the item. Returning back to Activity1 after Activity2 finishes I observe that the RecyclerView first draws the pre-Activity2 state (saved old item state), then in onActivityResult I do restartLoader() which delivers an updated set of data and then RecyclerView redraws itself again with the new data.
The problem with this behavior is that the RecyclerView flickers because it originally draws old data then redraws itself with the new data. Assuming I always want to use refreshLoader() in Activity1.onActivityResult(), is there a good way to avoid such flickering?
Additional complication is that I use empty view to show when recycleview is empty... This adds to flickering even more...
To remove update flickering on recycler view you can use:
RecyclerView.ItemAnimator animator = mRecyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
To update an items in RecyclerView you should use
notifyItemChanged(int position)
- Notify any registered observers that the item at position has changed.
instead of notifyDataSetChanged()
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