I am using a RecyclerView
with ListAdapter (which uses AsyncListDiffer to calculate and animate changes when list is replaced).
The problem is that if I
It defeats ListAdapter's purpose for automatically calculating and animating list changes when you call these lines consecutively:
submitList(null);
submitList(orderChangedList);
Meaning, you only cleared (null
) the ListAdapter's currentList and then submitted ( .submitList()
) a new List. Thus, no corresponding animation will be seen in this case but only a refresh of the entire RecyclerView.
Solution is to implement the .submitList( List
method inside your ListAdapter as follows:
public void submitList(@Nullable List list) {
mDiffer.submitList(list != null ? new ArrayList<>(list) : null);
}
This way you allow the ListAdapter to retain its currentList and have it "diffed" with the newList, thereby the calculated animations, as opposed to "diffing" with a null
.
Note: However, no update animation will happen, if, of course, the newList contains the same items in the same order as the originalList.