how to implement double click in android

Why dont you use Long Press event insted while its Recommanded UI. Read Answer Here , I strongly recommand to use this.

Or if its anyhow you want to implement you have two options , one is this using boolean and second is using Gesture Listener.


Try to use GestureDetector.

public class MyView extends View {

GestureDetector gestureDetector;

public MyView(Context context, AttributeSet attrs) {
    super(context, attrs);
    // creating new gesture detector
    gestureDetector = new GestureDetector(context, new GestureListener());
}

// skipping measure calculation and drawing

// delegate the event to the gesture detector
@Override
public boolean onTouchEvent(MotionEvent e) {
    //Single Tap
    return gestureDetector.onTouchEvent(e);
}


private class GestureListener extends GestureDetector.SimpleOnGestureListener {

    @Override
    public boolean onDown(MotionEvent e) {
        return true;
    }

    // event when double tap occurs
    @Override
    public boolean onDoubleTap(MotionEvent e) {
        float x = e.getX();
        float y = e.getY();

        Log.d("Double Tap", "Tapped at: (" + x + "," + y + ")");

        return true;
    }

}

Tags:

Android