We help IT Professionals succeed at work.

Android - get gestures from user on touch screen

GlobaLevel
GlobaLevel asked
on
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 ...
Comment
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:
mGestures.onTouchEvent(e);
.. then do any other handling.
4) Finally, implement onDoubleTap, onSingleTapConfirmed, callbacks to differentiate/handle the two events.

Hope that helps!
GlobaLevelProgrammer

Author

Commented:
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:
http://mobile.tutsplus.com/tutorials/android/android-gesture/
http://android-journey.blogspot.com/2010/01/android-gestures.html

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.