Reputation: 239
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
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