-
-
Save nesquena/b2f023bb04190b2653c7 to your computer and use it in GitHub Desktop.
Android DoubleTap Listener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Usage: | |
myView.setOnTouchListener(new OnDoubleTapListener(this) { | |
@Override | |
public void onDoubleTap(MotionEvent e) { | |
Toast.makeText(MainActivity.this, "Double Tap", Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
*/ | |
public class OnDoubleTapListener implements OnTouchListener { | |
private GestureDetector gestureDetector; | |
public OnDoubleTapListener(Context c) { | |
gestureDetector = new GestureDetector(c, new GestureListener()); | |
} | |
public boolean onTouch(final View view, final MotionEvent motionEvent) { | |
return gestureDetector.onTouchEvent(motionEvent); | |
} | |
private final class GestureListener extends SimpleOnGestureListener { | |
@Override | |
public boolean onDown(MotionEvent e) { | |
return true; | |
} | |
@Override | |
public boolean onDoubleTap(MotionEvent e) { | |
OnDoubleTapListener.this.onDoubleTap(e); | |
return super.onDoubleTap(e); | |
} | |
} | |
public void onDoubleTap(MotionEvent e) { | |
// To be overridden when implementing listener | |
} | |
} |
Hi, I want to detect single tap and double tap for same view. Could you please suggest me an idea?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@nesquena thanks!! I implement one tab by this documentation!