In fact, with the previously mentioned code (which you can find here below), all RecyclerView child elements are animated when one element is deleted, and this is not an adaptive solution at all, including due to potential hidden problems.
public void remove(int position) { dataset.remove(position); notifyItemRemoved(position); notifyItemRangeChanged(position, mDataSet.size()); }
Instead, the following snippet will only play the animation for the child being deleted, and for my part, it stopped IndexOutOfBoundException marked by the debugger as "data mismatch."
void remove(int position) { dataset.removeAt(position); notifyItemChanged(position); notifyItemRangeRemoved(position, 1); }
If we delve into the RecyclerView class, we can find a piece of javadoc that has an explanation, indeed, as the second parameter, we must pass the number of elements that are removed from the data set, and not the total number of elements
public final void notifyItemRangeRemoved(int positionStart, int itemCount) { mObservable.notifyItemRangeRemoved(positionStart, itemCount); }
Andrea Cioccarelli Jun 19 '18 at 11:15 2018-06-19 11:15
source share