OneAdapter: Invalid view holder adapter position

Hi, 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.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 24 (9 by maintainers)

Most upvoted comments

@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.

@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 😃

v1.5.1 is out closing (hoping for good this time)