views:

588

answers:

1

Hello,

I have a ImageView and draw some things on that view. Now I want to have the position of the click in the onClickListener.

Although I think that's not really possible (storing the position in the onTouchListener is not working), I want to ask, if there is any other way to accomplish that?

The goal is to have a image with some overlays, that should be clickable. I thought about AbsolutLayout, but that is depracated, so what now?

Thx for any help.

+1  A: 

Storing position in onTouchListener should work. Did you return false in your onTouchListener ? If you return true, the onClick will never be called. Also note that click can be performed on android without using touch functionality on the device in example by using hardware button. In my opinion you should not use onClickListener for what you're doing, instead handle everything from onTouchListener by handling ACTION_UP as your click event.

Code for android onClick implementation can be found here: http://www.google.com/codesearch/p?hl=en#uX1GffpyOZk/core/java/android/view/View.java&q=android.view.View.java&sa=N&cd=1&ct=rc check the onTouchMethod, it calls performClick method.. which does what it says it does :).

Ivan
That's a bit of a complicated example for a simple touch event! :P See this other question for a simple onTouchEvent: http://stackoverflow.com/questions/2609114/android-beginner-understanding-motionevent-actions/2609435#2609435
Steve H
Thx for your answer. I'am now handling the click in the onTouch method, but listening to ACTION_DOWN instead of ACTION_UP, that works fine for me.
Masala