I have a RelativeLayout I am putting a TouchListener into using GestureDetector. I have already done and can detect double tapping but how can I add a swipe event in the view also?
private void myTapEvent(){
RlContent.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
});
gestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDoubleTap(MotionEvent e) {
count++;
doTaskHere();
return true;
}
@Override
public boolean onDown(MotionEvent e) {
return true;
}
});
}
After implementing a swipe event, how can I switch between
a.) allowing tapping only and disabling swiping
and
b.) disabling tapping and allowing swiping only.
In your
GestureDetectorlistener, add theonFlingmethod. Additionally, to switch between them, you will want abooleanvariable in your class that can be switched.There are some examples of swipe using fling here and here, and there’s plenty more if you scour Google a bit.