2

I have a ListView showing in each row three things (left icon, middle text, right icon). When the user "clicks" on a row, I want to do an action depending on the horizontal position of the "click", but there's no x-coordinate in AdapterView.OnItemClickListener.onItemClick nor do I have any idea what to do instead.

I don't need the exact coordinate, an information like "left/middle/right" would suffice. Knowing which of the three things was touched is about the same. I've found this answer, but I doubt it's related. Is it? Is there a way how to get the x-coordinate?

Or should I try GridLayout?

Community
  • 1
  • 1
maaartinus
  • 44,714
  • 32
  • 161
  • 320

1 Answers1

0

If you want to get the exact coordinates of a click, you need to set onTouchListener instead on the view that you want receive events for.

From this, you'll get the MotionEvent which you can use to figure out the coordinates and pretty much anything else you'd want to know.

hwrdprkns
  • 7,525
  • 12
  • 48
  • 69
  • Works like charm... I only save the `event.getX() / view.getWidth()` into a global variable and later in `onItemClick` use it to decide what to do. – maaartinus Sep 16 '12 at 07:20