Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect doubletap on a View? [duplicate]

Possible Duplicate:
Android - basic gesture detection

I'm trying to have a View sensitive to double taps on an Android. So far, I learned to set up the double tap and know what place to handle the event for action:
API: android.view.GestureDetector.OnDoubleTapListener

    private GestureDetector mGestureDetector;
    …
    mGestureDetector = new GestureDetector(this);
    …
    mGestureDetector.setOnDoubleTapListener(new MyDoubleTapListener());
    …
    private class MyDoubleTapListener implements GestureDetector.OnDoubleTapListener {
    public boolean onDoubleTapEvent(MotionEvent e) {                         
                                    return false;                      
    }
                    @Override
                    public boolean onDoubleTap(MotionEvent e) {
                                    // TODO Auto-generated method stub
                                    return false;
                    }

                    @Override
                    public boolean onSingleTapConfirmed(MotionEvent e) {
                                    // TODO Auto-generated method stub
                                    return false;
                    }
}


But How do I link it to the View? This is in a class that has a few View members.

I'll really appreciate you helping me connect the dots!

like image 262
Johnson Tey Avatar asked Apr 14 '10 18:04

Johnson Tey


People also ask

How do you detect double tap?

I use GestureDetector in custom View . The method onDoubleTap(MotionEvent) from the type new GestureDetector. OnGestureListener() {} is never used locally. Then I tried to test whether this works and made a function to change TextView string whenever I DoubleTap .


1 Answers

Your view needs to implement the onTouchEvent() method, and that method needs to pass the event along to the onTouchEvent() method of the GestureDetector object.

@Override
public boolean onTouchEvent(MotionEvent event) 
{
    Log.v(DEBUG_TAG,"OnTouchEvent !!!");
    boolean result = gestureScanner.onTouchEvent(event);//return the double tap events
    return result;
}
like image 72
Mike Fulton Avatar answered Sep 18 '22 21:09

Mike Fulton