OK, a little experiment on my part has yielded the following information.
Also, I'm a little confused - the prototype for the onTouch() method
includes a View object - the view that received the event. Why do you need
to find the view that was touched when it is being *given* to you in the
handler?
As far as I know (my Android experience is very limited, so someone may be
able to correct me here), events are only dispatched to the widget / view
that they occur on,
I can confirm that events, including onTouch(), do *not* go to any view
*other* than the one on which the handler was set. Therefore, the View
passed in onTouch() *is* the view that received the event - the button, in
your case.
3.Single pointer (i.e just ACTION_DOWN)also doesn't identify the view.
OK, the documentation is the problem here - it is not good enough. When I
read the details against getX(), it has AXIS_X as a 'See also', and when you
go there, it says co-ordinates are given in screen co-ordinates. For getX()
and getY(), however, this is *incorrect*. Whether it is correct for AXIS_X I
don't know or care, but for the onTouch event and getX() and getY()
purposes, the values from those two functions are *relative* to the top-left
of the view's (button's) client area - in other words if you touched at
exactly the top-left corner, it would give 0, 0 - if you touched exactly at
the bottom-right corner, it would give (width - 1, height - 1).
Thus, your test is not really needed, since the correct view is passed to
you - and even if you wanted to find the view yourself, you can't since you
are being given relative client co-ordinates, not screen co-ordinates. You
can't even convert those values to screen since you'd need to know which
view they are relative to in the first place to be able to convert them!
Hopefully that helps.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en