First let ur Activity implements OnTouchListener
then
return the gesture detector i.e as follows
public boolean onTouch(final View view, final MotionEvent motionEvent) {
// TODO Auto-generated method stub
return gestureDetector.onTouchEvent(motionEvent);
}
then
now
urpage.setOnTouchListener(this);
in onCreate method
Next
create a class called GestureListener
in that
private final class GestureListener extends SimpleOnGestureListener {
private static final int SWIPE_THRESHOLD = 100;
private static final int SWIPE_VELOCITY_THRESHOLD = 100;
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
boolean result = false;
try {
float diffY = e2.getY() - e1.getY();
float diffX = e2.getX() - e1.getX();
if (Math.abs(diffX) > Math.abs(diffY)) {
if (Math.abs(diffX) > SWIPE_THRESHOLD
&& Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
if (diffX > 0) {
//dynamic load the page which you want when the user swipes left side
} else {
//dynamic load the page which you want when the user swipes right side
}
}
}
} catch (Exception exception) {
exception.printStackTrace();
}
return result;
}