android swipe gesture functions

111 views Asked by At

can anyone tell me how to add functions in swipe gesture? e.g onSwipeRight(), i don't want make a toast instead calculate from one to ten how much the screen was swiped and then store that data in some variable? like the samsung galaxy s5 image editor does while changing the brightness of the image

imageView.setOnTouchListener(new OnSwipeTouchListener() {

    public void onSwipeRight() {
        Toast.makeText(MyActivity.this, "right", Toast.LENGTH_SHORT).show();
    }

    public void onSwipeLeft() {
        Toast.makeText(MyActivity.this, "left", Toast.LENGTH_SHORT).show();
    }


    public boolean onTouch(View v, MotionEvent event) {
        return gestureDetector.onTouchEvent(event);
    }
});
1

There are 1 answers

0
nuuneoi On

Use GestureDetector to detect onFling or just use OnSwipeTouchListener from https://stackoverflow.com/a/19506010/4651112