Reputation:
I'm working on the android app. In my app i want to move from first activity to second activity by swiping and by click on the tab button.
so please tell me how i can use the swipe in my app for moving to next activity when i swap from Right to left and come back on first activity when i swap Left to right.
Thanks.
Upvotes: 0
Views: 147
Reputation: 2605
let your activity implement OnGestureListener
and then override this method
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Intent i=new Intent(GroupScreen.this,TimeLineScreen.class);
i.putExtra("clear", true);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish();
overridePendingTransition( R.anim.slide_in_left, R.anim.slide_out_left );
} catch (Exception e) {
// nothing
}
return true;
}
Upvotes: 0
Reputation: 1827
You can use a GestureDector to get callbacks for left and right swipe motion. http://developer.android.com/reference/android/view/GestureDetector.html
Upvotes: 1