I am running into an issue with the RecyclerView#Adapter
regarding notifyItemRangeChanged
. It seems that if the Adapter
thinks it has
Is this the expected behavior?
Short answer: yes.
From the docs on notifyDataSetChanged() (yes, different method, I know, but just referencing it here since it explains the difference between item changes and structural changes):
There are two different classes of data change events, item changes and structural changes. Item changes are when a single item has its data updated but no positional changes have occurred. Structural changes are when items are inserted, removed or moved within the data set.
Now have a read through the documentation on notifyItemRangeChanged() (my emphasis):
This is an item change event, not a structural change event. It indicates that any reflection of the data in the given position range is out of date and should be updated. The items in the given range retain the same identity.
That should answer your question. You're making a structural change (that is, you're adding an item), hence notifyItemRangeChanged()
is not the appropriate method to call. Instead, you should call notifyItemRangeInserted() (or its singular equivalent), which does indicate a structural change was made.