Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PointToPosition Alternative for RecycleView

I'm replacing a ListView by the RecyclerView, but I'm using a pointToPosition method, is there any equivalent?


like image 690
ademar111190 Avatar asked Feb 10 '23 14:02

ademar111190


2 Answers

For RecyclerView you have findChildViewUnder (float x, float y). This method returns a child View which you can then use to retrieve the adapter position using getChildAdapterPosition(View child).

like image 123
paprikanotfound Avatar answered Feb 15 '23 10:02

paprikanotfound


This will get you the View at (x, y) in the parent RecyclerView:

View targetView = recyclerView.findChildViewUnder(x, y);

And this gets you the position of the item within the underlying data set currently represented by that View:

recyclerView.getChildAdapterPosition(targetView);
like image 29
Radu Topor Avatar answered Feb 15 '23 09:02

Radu Topor