Home » Android » android – What's the alternative to .notifyItemInserted() for multiple items?-Exceptionshub

android – What's the alternative to .notifyItemInserted() for multiple items?-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I’m using a RecyclerView and .notifyItemInserted only inserts one item into the RecyclerView. How would I do that say, for multiple items? I want to AVOID using .notifyDataSetChanged().

Say I have 25 items, I want to insert another 20, what method would I call?

How to&Answers:

You can use notifyItemRangeInserted to notify for multiple insertion.

void notifyItemRangeInserted (int positionStart, int itemCount)

According official documentation

Notify any registered observers that the currently reflected itemCount
items starting at positionStart have been newly inserted. The items
previously located at positionStart and beyond can now be found
starting at position positionStart + itemCount.