We help IT Professionals succeed at work.

Android - get gestures from user on touch screen

GlobaLevel asked
I need to get the values of gestures that a user registers on the touch screen so if they tap one launches this method, if they tap twice launches this method ...
Watch Question

Doing this off the top of my head...

1) add GestureDetector.OnDoubleTapListener to the interfaces list for your view class
2) early in creation of your view (constructor usually), create the gesture handler, like:
mGestures = new GestureDetector(context, this);
That makes a gesture detector object (which, obviously, needs to be a member of the view class..) that will dispatch any gestures to the view as callbacks.
3) in the view's onTouchEvent handler, let the gesture handler have first shot:
.. then do any other handling.
4) Finally, implement onDoubleTap, onSingleTapConfirmed, callbacks to differentiate/handle the two events.

Hope that helps!


thanks so much...would you have any sample code by any chance?
I don't have any personal code that I'd paste in, but quick google showed two tutorials/samples on the net that looked okay in brief review:

The first one uses a separate class/object for the gesture listening.  The second one just adds the listener interfaces directly to the activity itself.  Which you use is personal preference.