Android: custom view onClickEvent with X & Y locations
- by Martyn
Hi,
I've got a custom view and I want to get the X and Y coordinates of a user click. I've found that I can only get the coordinates from the onTouchEvent and an onClickEvent won't fire if I have an onTouchEvent. Unfortunately the onTouchEventfires when the user drags the screen as well as clicking.
I've tried to differentiate between the two, but I still get the code firing when I'm dragging:
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_DOWN) {
//fires on drag and click
I've had a look at this but as I mentioned above I don't think the solution there will work as I can't get the onClick and the onTouch events working at the same time. Maybe I'm doing something wrong in this respect, is there a normal way of dealing with capturing user input on custom events? Should I be able to use the onClick and onTouch events at the same time?
Thanks, Martyn