Saturday, 23 December 2017

RecyclerViewAdapter java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder


RecyclerViewAdapter java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder


My app crashes if i scroll this list view when it is loading data.

I can find a lot of post online, but no right solutions to fix this. Couple of them recommend to override Layoutmanager and stop animations. But none of them solved my issue.

I eventually found that, every time I load data, I will clear all data and then process data and add items one by one, I send "notifyDataSetChanged" for each new item.

because after i cleared items, but i didn't notify the view, so it get confused about how many items is in the component.

My solution is notifyDataSetChanged after i cleared the list and notifyDataSetChanged again when i add new items in.

No comments:

Post a comment