Search code examples
javascriptandroiddouble-clickgesturedetector

Android How to detect double tap?


I'm trying to refresh Canvas on DoubleTap in android. I use GestureDetector in custom View.

final GestureDetector mDetector = new GestureDetector(
    getContext(), new GestureDetector.OnGestureListener() {

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

But I'm getting the error

The method onDoubleTap(MotionEvent) of type new GestureDetector.OnGestureListener(){} must override or implement a supertype method

with

Remove '@Override' annotation

solution. I remove override and get this warning

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. Nothing happens.

I also looked at GestureDetector Reference for explanations, but they don't even have DoubleTap there, which everybody uses. What should I do?


Solution

  • try this

    final GestureDetector mDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener {
    
        @Override
        public boolean onDown(MotionEvent e) {
    
            return true;
        }
    
        @Override
        public boolean onDoubleTap(MotionEvent e) {
    
            return true;
        }
    });