How do I use double tap events in an activity? The double tap event or long click method working (though the method is getting overriden) I've just put in a toast message in each of these methods and yet no result! Can you help?
The easiest way to do a double-tap is to detect it with a GestureDetector. The "trick" is to be sure you delegate the Activity's onTouchEvent to the GestureDetector's onTouchEvent:
import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.widget.Toast;
public class MainActivity extends Activity {
    private GestureDetector gestureDetector;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onDoubleTap(MotionEvent e) {
                Toast.makeText(MainActivity.this, "double tap", Toast.LENGTH_SHORT).show();
                return true;
            }
        });
    }
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (gestureDetector.onTouchEvent(event))
            return true;
        return super.onTouchEvent(event);
    }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With