Jessica
Jessica

Reputation: 715

Get absolute coordinates of an Item in GridView Android

I want to get absolute coordinates (X, Y) of an item in a GridView.

I have position of this item in the GridView.

How can I get X, Y of this Item on the screen?

I wish there was positionToPoint instead of pointToPosition!

Upvotes: 3

Views: 1149

Answers (1)

Nishant Srivastava
Nishant Srivastava

Reputation: 4791

As far as i understand your question ,you can use pointToPosition method , available in GridView Android API

if (myGridView.pointToPosition((int)e.getX(), (int)e.getY())!=-1) {
 myItem = myGridViewAdapter.getItem(myGridView.pointToPosition((int)e.getX(), (int)e.getY()));
}

Upvotes: 1

Related Questions