I have SwipeActivity. when I swipe from right to left, I want to go activity B and when swipe left to right go to activity C. but my code didn't work. please help me.
my SwipeActivity is:
public class SwipeActivity extends Activity {
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final GestureDetector gestureDetector = new GestureDetector(new GestureListener()); View mainview = (View) findViewById(R.id.mainView); // Set the touch listener for the main view to be our custom gesture listener mainview.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (gestureDetector.onTouchEvent(event)) { return true; } return false; } }); } 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) { onSwipeRight(); } else { onSwipeLeft(); } } } } catch (Exception exception) { exception.printStackTrace(); } return result; } } public void onSwipeRight() { Intent in = new Intent(SwipeActivity.this,page1Activity.class); startActivity(in); } public void onSwipeLeft() { Intent in = new Intent(SwipeActivity.this,page2Activity.class); startActivity(in); } }