Invalid view holder adapter position
See original GitHub issueHi, the library is really great due to its modular design. It really does help a lot.
Unfortunately I have encountered an issue. I will first show some code, but I do not have a small, executable example at the moment, I might add it later.
My code uses the OneAdapter as follows:
Within the fragment:
recyclerView = view.findViewById(R.id.ingredients_list);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
oneAdapter = new OneAdapter(recyclerView);
oneAdapter.attachEmptinessModule(new PantryEmptinessModule());
oneAdapter.attachPagingModule(new PantryPagingModule());
oneAdapter.attachItemModule(new PantryItemModule());
prepopulateAdapter();
Within prepopulateAdapter (on main thread):
oneAdapter.add(recipes); //recipes is an ArrayList
Within PantryPagingModule:
@Override
public PagingModuleConfig provideModuleConfig() {
return new PagingModuleConfig() {
@Override
public int withVisibleThreshold() {
return 3;
}
@Override
public int withLayoutResource() {
return R.layout.load_more_item;
}
};
}
@Override
public void onLoadMore(int i) {
//Recipes are obtained in the background...
//on main thread
oneAdapter.add(recipes); //recipes is an ArrayList
}
The item looks as follows:
@PrimaryKey
public int id;
@ColumnInfo(name = "name")
public String name;
@ColumnInfo(name = "amount")
public int amount;
@Override
public boolean areContentTheSame(@NotNull Object o) {
if (!(o instanceof Recipe)) {
return false;
}
Ingredient other = (Recipe) o;
boolean names = this.name.equals(other.name);
boolean amount = this.amount == other.amount;
return names && amount;
}
@Override
public long getUniqueIdentifier() {
return id;
}
And the error message that sometimes comes when scrolling is:
ava.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder
Now, I have no idea where this error might come from. Maybe we can find a solution to this and fix it. If any more information is needed, I’ll be happy to help. Thanks in advance.
Issue Analytics
- State:
- Created 4 years ago
- Comments:24 (9 by maintainers)
Top Results From Across the Web
RecyclerView and java.lang.IndexOutOfBoundsException ...
RecyclerView and java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder in Samsung devices.
Read more >Inconsistency detected. Invalid view holder adapter ... - GitHub
I followed a basic usage tutorial and I got a exception: Process: com.example, PID: 13642 java.lang.IndexOutOfBoundsException: Inconsistency detected.
Read more >RecyclerView doesn't properly clear state when setAdapter ...
I'm facing an issue with RecyclerView that seems to be related with it not clearing the state properly when setAdapter() is called. The...
Read more >Solution for RecyclerView — IndexOutOfBoundsException
Invalid Item ## Item Position, etc. Let's see a few ways to fix this. Understand why this happens. When the user scrolls your...
Read more >RecyclerView.Adapter - Android Developers
Returns the position of the given ViewHolder in the given Adapter . If the given Adapter is not part of this Adapter ,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@meruiden Please try
recyclerView.setItemAnimator(null);
I was also having the same problem and this line solved the issue. I am not sure why this is happening but this helped me to get the problem solved. It is most probably occurring due the Diffable implementation of the model class.
You saved my life, i spent several days looking for a solution and this line made my day man 😃