In my application, I need to handle both move and click events.
A click is a sequence of one ACTION_DOWN action, several ACTION_MOVE actions and one ACTION_UP action
Below code will solve your problem
@Override
public boolean onTouchEvent(MotionEvent event) {
switch(event.getAction()) {
case(MotionEvent.ACTION_DOWN):
x1 = event.getX();
y1 = event.getY();
break;
case(MotionEvent.ACTION_UP): {
x2 = event.getX();
y2 = event.getY();
dx = x2-x1;
dy = y2-y1;
if(Math.abs(dx) > Math.abs(dy))
{
if(dx>0) move(1); //right
else if (dx == 0) move(5); //click
else move(2); //left
}
else
{
if(dy>0) move(3); // down
else if (dy == 0) move(5); //click
else move(4); //up
}
}
}
return true;
}