I have a ListView with some focusable components inside (mostly EditTexts). Yeah, I know this isn\'t exactly recommended, but in general, almost everything is w
I'm using RecyclerView and none of the presented solutions worked. I got the error when removing items.
What did work was overriding the Adapter's 'onItemDismiss(int position)' so that it first does a 'notifyDataSetChanged()' prior to removing the item and then does 'notifyItemRemoved(position)' after removing the item. Like this:
// Adapter code
@Override
public void onItemDismiss(int position) {
if (position >= 0 && getTheList() != null && getTheList().size() > position) {
notifyDataSetChanged(); // <--- this fixed it.
getTheList().remove(position);
scrollToPosition(position);
notifyItemRemoved(position);
}
}
Also do an Override of 'removeAt(int position)' in the TabFragment to invoke the new cleanup code, like this:
// TabFragment code
@Override
public void removeAt(int position) {
mAdapter.onItemDismiss(position);
mAdapter.notifyItemRemoved(position); // <--- I put an extra notify here too
}