0

i want to doble click event for button.Can any one give me a idea.

thanx

user321
  • 37
  • 3
  • double click for a button in fone? Why? Why not use single click as double click and press and hold for single click – Shoban Oct 16 '12 at 07:33
  • i think there is no implementation of that in the framework. try to use a timer – x4rf41 Oct 16 '12 at 07:34
  • http://stackoverflow.com/a/4849304/966550 – waqaslam Oct 16 '12 at 07:36
  • I develop a application for visual impaired.So currently i used long press to navigate the page.But its not effective for blind people.So i need doble click event. – user321 Oct 16 '12 at 07:42
  • possible duplicate of [Implement double click for button in Android](http://stackoverflow.com/questions/4849115/implement-double-click-for-button-in-android) – guido Oct 16 '12 at 11:44

1 Answers1

2

Why aren't you using a Long Press? Or are you using that already for something else? The advantages over a long touch over a double touch:

  1. Long Press is a recommeded interaction in the UI Guidelines, double touch is not.
  2. It's what users expect; a user might not find a double touch action as they won't go looking for it
  3. It's already handled in the API.
  4. Implementing 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.

If u want double click : you can use the GestureDetector.

See the following code:

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) {
    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;
    }
}
}
Okky
  • 10,338
  • 15
  • 75
  • 122