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);
}
});
Use
GestureDetector
to detectonFling
or just useOnSwipeTouchListener
from https://stackoverflow.com/a/19506010/4651112