3

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

Bartek Lipinski
  • 30,698
  • 10
  • 94
  • 132
user3422687
  • 229
  • 1
  • 8
  • 27

1 Answers1

12

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).

Buzz
  • 516
  • 7
  • 21
  • Thaks for that I have looked at the code and im sure your right but have no idea how too fix it. My complete code is too long to post here so can be viewed here https://www.dropbox.com/s/tsahec4yy9rxw75/SubsamplingScaleImageView.java?dl=0 or is tere a way of detecting if two instances of an activity is there and close one as when I double tap this runs another activity but does it twice – user3422687 Jan 23 '15 at 08:30
  • YOUR GODDAM RIGHT! – Arthur Melo Oct 21 '19 at 16:43