I have a view that need to process onTouch gestures and onClick events. What is the proper way to achieve this?
I have an onTouchListener
and
we can use flag based implementation. where swipe/dragging we can handle in Action_Up and make the flag true and return the same. In Case of click or Tap same handle in Action_Down and set the flag false and return.
touchAndSwipe=false;
switch(e.getAction()){
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_DOWN:
x1 = e.getX();
break;
case MotionEvent.ACTION_UP:
x2 = e.getX();
float diff = x2 - x1;
if(Math.abs(delta) > 100) {
// Swipe
touchAndSwipe = true;
} else {
touchAndSwipe = false;
}
break;
}
return touchAndSwipe;