Wrong position when removing multiple items
See original GitHub issueHi 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 onBindViewHolder
when 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
Issue Analytics
- State:
- Created 6 years ago
- Comments:16 (8 by maintainers)
Top GitHub Comments
globalPosition is the real one for the Adapter point of view.
Sorry @henengel, please use Snapshot version (published yesterday eve) if you consider it better, read last post in issue 39 for release notes. I will be busy for the time being.
Regarding the ClassCast it will take some time and debugging from your side, better if you search on Internet. I see that the codes references are completely different in the 2 lists you’ve shown me. So they are different object in memory too. I really do not know how your use case works and the whole code running behind.