Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getAdapterPosition() can be wrong #15

Open
scriptacus opened this issue Aug 6, 2015 · 2 comments
Open

getAdapterPosition() can be wrong #15

scriptacus opened this issue Aug 6, 2015 · 2 comments

Comments

@scriptacus
Copy link

This isn't a bug with this code, but I'm throwing it out there as a potential gotcha that I only ran into after implementing the dismiss/swap functionality from this demo.

After a dismiss or swap of items in a recycler view, "holder.getAdapterPosition()" will return NO_POSITION (-1) if you've called "notifyDataSetChanged()" since the last layout pass. I was passing getAdapterPosition() to my Activity in response to some user interaction, which had always worked previously. After either of the actions above, the adapter position became invalid until an orientation change or attempt to scroll the screen. Using getLayoutPosition() in place of getAdapterPosition() resolved the issue.

@Farasy
Copy link

Farasy commented Sep 11, 2015

Thanks for info.

@pixelbendr
Copy link

Yes I noticed this, my app start crashes sometimes on swipe; when I run the test getAdapterPosition is -1. :( is there a fix for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants