user3422687
user3422687

Reputation: 239

Android Double Tap Fires Twice

I used the following double tap code

setOnTouchListener(this);
detector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
    @Override
    public boolean onDoubleTapEvent(MotionEvent ev) {
        int x = (int)ev.getX();
        int y = (int)ev.getY();
        Toast.makeText(getContext(), "Double tapped", Toast.LENGTH_LONG).show();
    }
});

When I run it runs the toast twice

Any ideas?

Running on KitKat 4.4

Any help appreciated

Mark

Upvotes: 3

Views: 982

Answers (1)

Buzz
Buzz

Reputation: 516

This is probably happening because the onDoubleTapEvent notifies on the down, move and up events. In your case you have the up and down events which are causing the toast to display twice. If you just want to verify that the double-tap has been detected successfully you can use onDoubleTap(MotionEvent e) instead of onDoubleTapEvent(MotionEvent ev).

Upvotes: 12

Related Questions