Android: How to Detect Double-Tap

Android How to detect double tap?

try this

final GestureDetector mDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener {

@Override
public boolean onDown(MotionEvent e) {

return true;
}

@Override
public boolean onDoubleTap(MotionEvent e) {

return true;
}
});

Android: How to detect double-tap?

Why aren't you using a Long Press? Or are you using that already for something else? The advantages of a Long Press over a Double Touch:

  • Long Press is a recommeded interaction in the UI Guidelines, Double Touch is not.
  • It's what users expect; a user might not find a Double Touch action as they won't go looking for it
  • It's already handled in the API.
  • Implementing a Double Touch will affect handling of Single Touches, because you'll have to wait to see if every Single Touch turns into a Double Touch before you can process it.

How detect double tap left and right in android on any type of view

1) You could get coords of tap from MotionEvent object, calculate center of target view (via x,y, height, width) and then handle this data;

2) You could use two transparent overlays and set listeners to them )

Android detecting double tap without single tap first

I'm confused on what you're trying to achieve. The double tap method onDoubleTap() isn't called when the single tap occurs. On the other hand, for every double tap there are two associated single tap onSingleTapUp() method calls.

If you want to distinguish them, you can use onSingleTapConfirmed() which is triggered when the gesture detector is sure the tap is single. See reference:

Notified when a single-tap occurs.

Unlike OnGestureListener.onSingleTapUp(MotionEvent), this will only be called after the detector is confident that the user's first tap is not followed by a second tap leading to a double-tap gesture

You can then use this method call in combination with a boolean flag to essentially detect any type of single/double tap.



Related Topics



Leave a reply



Submit