FlexibleAdapter: Wrong position when removing multiple items

Hi David, in continuation to other issues we worked on last week, I encountered this one too. Since it’s an issue that is not related to other issues we had, I thought it would be better to open a new ticket to better address the problem, and for other users to be able to solve this particular issue in case they have it too. The problem I have is the position I get in onBindViewHolderwhen removing multiple items. Scenario: I create multiple DFP banners ad requests. Inside the onBind method, I have a listener that is invoked if the banner fails to load. In that case, I try to remove the item.

Relevant code: At first I tried:

mDataUtils.removeItemFromData(position);
adapter.notifyItemRemoved(position);
adapter.notifyItemRangeChanged(position, mDataUtils.getCurrentDataSet().size());

In other isuues to say that there is no need to use notify*** mehtods, so I then tried:

mDataUtils.removeItemFromData(position);
adapter.updateDataSet(new ArrayList(mDataUtils.getCurrentDataSet()),false);

Both didn’t do the trick.

The issue: When removing the first item of multiple ones, the position I get in the onBindViewHolder method of the item is ok and no problem.

After that, every other item I remove, the position of the item I get is invalid. I think it has to do with the range not being updated and hence, resulting in getting the wrong position of the item.

Any suggestions? #324

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

globalPosition is the real one for the Adapter point of view.