Okay I have been referencing the code here: Fling gesture detection on grid layout
but just can not get it to work. In my main activity I have a simple image define
Design your layout with ImageView.
Add setOnTouchListenerto imageView.imageview.setOnTouchListener(this).add unimplemented method View.OnTouchListener.Then onTouch method you can implemtn your guesture logic.This sample tells you left to right and right to left guesture,
float x1,x2;
float y1, y2;
@Override
public boolean onTouch(View view, 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();
if ( x1x2 ) {
//implement what you need to do here
}
break;
}
}
return false;
}