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

get the position of a View #12

Closed
nitrico opened this issue Jan 29, 2015 · 3 comments
Closed

get the position of a View #12

nitrico opened this issue Jan 29, 2015 · 3 comments

Comments

@nitrico
Copy link

nitrico commented Jan 29, 2015

Is it possible that this adapter "breaks" the RecyclerView.LayoutManager.getPosition(View view) ? It is always returning -1. Maybe I'm not doing it correctly but I think I am.

@StanKocken
Copy link
Owner

Just tested and no, I'm able to retrieve the correct position on my side.

mRecyclerView.getLayoutManager().getPosition(mRecyclerView.getChildAt(0)) == 0
mRecyclerView.getLayoutManager().getPosition(mRecyclerView.getChildAt(1)) == 1

Did you try with the method:

mRecyclerView.getChildPosition(mRecyclerView.getChildAt(0)) ?

It should return the same thing.

@nitrico
Copy link
Author

nitrico commented Jan 31, 2015

So I must be doing something wrong somewhere else cause both method are returning me -1. By the way, is there a way to get the LayoutManager from inside a viewholder?

Thank you so much for the answer and for the library!

@StanKocken
Copy link
Owner

Sorry to hear that, I hope you will find the issue. If you want, you can test with my sample available on this repo and let me know.

I think you can get the LayoutManager from a ViewHolder, by calling the parent of "getView()" (it's your RecyclerView), then call getLayoutManager on it.

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

2 participants