Recognizing tap and other common gestures
Unlike the Event Listeners described in the previous recipe, gestures require a two-step process:
- Gather the movement data
- Analyze the data to determine whether it matches a known gesture
Step 1 begins when the user touches the screen, which fires the onTouchEvent()
callback with the movement data sent in a MotionEvent
object. Fortunately, Android makes Step 2, analyzing the data, easier with the GestureDetector
class, which detects the following gestures:
onTouchEvent()
onDown()
onFling()
onLongPress()
onScroll()
onShowPress()
onDoubleTap()
onDoubleTapEvent()
onSingleTapConfirmed()
This recipe will demonstrate using the GestureDetector.SimpleOnGestureListener
to recognize the touch and double tap gestures.
Getting ...
Get Android Application Development Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.