Is this the expected behavior?
The short answer is yes.
From the documents notifyDataSetChanged() (yes, I know, another method, but just referring to it here, as it explains the difference between element changes and structural changes ):
There are two different classes of data change events, element changes, and structural changes. Element changes - this is when one element has updated data, but no position changes have occurred. Structural changes are when elements are inserted, deleted, or moved within a dataset.
Now read the documentation for notifyItemRangeChanged() (my emphasis):
This is an element change event, not a structural change event. . This means that any data reflection in this position range is outdated and needs to be updated. Elements in a given range retain the same identity.
This should answer your question. You are making structural changes (i.e., notifyItemRangeChanged() an element), so notifyItemRangeChanged() not a suitable method to call. Instead, you should call notifyItemRangeInserted() (or its singular equivalent), which indicates a structural change.
source share