0

I have a recycler view and an array of positions to be deleted.

Now when i delete the items using a loop , after deletion of item at position 1, the total number of items in Recyclerview decreases hence the rest positions point to wrong rows . Thereby leading to IndexOutofBound Exception.

Therefore what could i do to properly delete multiple recyclerview items at once if i know their initial positions?

Naimish Srivastava
  • 373
  • 1
  • 3
  • 14
  • either use an iterator, or traverse the list from last-to-first when deleting multiple items. see here: https://stackoverflow.com/questions/1196586/calling-remove-in-foreach-loop-in-java – Daniel Nugent Jun 21 '17 at 22:40
  • Also take a look at this tutorial: https://bignerdranch.github.io/recyclerview-multiselect/ You can see that in the `onActionItemClicked()` method, they iterate from last-to-first, and call `mRecyclerView.getAdapter().notifyItemRemoved(i);` on each item the user marked for deletion. – Daniel Nugent Jun 21 '17 at 22:49

0 Answers0