What's the alternative to .notifyItemInserted() for multiple items?

Mike Litoris :

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?

Md. Asaduzzaman :

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.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=7238&siteId=1