Reputation: 31161
In Android, we can set OnClickListeners
for views.
But how do we intercept the location of the touch event?
Upvotes: 0
Views: 1888
Reputation: 37729
there is method in Activity
public boolean onTouchEvent(MotionEvent event){
int action = event.getAction();
int x = event.getX()
int y = event.getY();
return yourBoolean;
}
Edit: Or you can define OnTouchListener
for any View
and can use its method
public abstract boolean onTouch(View v, MotionEvent event);
Edit2: the x
and y
values depends upon the method call. If you use onTouchEvent()
of Activity
then it indicates that no View
consumes the touch event see documentation and if you handle it on any View
then the x and y will be according to the View
's area.
Upvotes: 2
Reputation: 24235
You can set the onTouchListener
for the same view. The MotionEvent
will have the x and y.
Upvotes: 1