question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong position when removing multiple items

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
davideascommented, Apr 5, 2017

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

0reactions
davideascommented, Apr 6, 2017

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to remove multiple items from a list in just one statement?
It allows removing multiple values or removing only duplicates of these values and returns either a new list or modifies the given list...
Read more >
Remove element from a Python LIST [clear, pop, remove, del]
Python pop() method; Python clear() method; Using del keyword; How do I remove the first element from a list? How do I remove...
Read more >
How to remove a specific item from Array? | by D DEV - Medium
Here we go! We have compiled a list of all possible ways of removing an item, from a specific position in an array....
Read more >
Removing Items from an Array in JavaScript - Ultimate Courses
In this article, we'll explore a few different ways to remove an item from an array in JavaScript. I will also show you...
Read more >
delete operator - JavaScript - MDN Web Docs - Mozilla
If the property's value is an object and there are no more references to ... delete can be used to remove properties from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found