Ajay Soman
Ajay Soman

Reputation: 1651

Double tap event in android

I need to toast something on double tap the screen. I tried the following code. But it's not working. No toast is coming on double tapping. What is wrong with these code?

package a.b.c;

import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.widget.Toast;



public class SampleActivity extends Activity implements OnDoubleTapListener,OnGestureListener
{
        @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    @Override
    public boolean onDoubleTap(MotionEvent e) {
        if(e.getAction()==1)
        {
        Toast.makeText(getBaseContext(), "onDoubleTap", Toast.LENGTH_LONG).show();
        }
        return true;
    }

    @Override
    public boolean onDoubleTapEvent(MotionEvent e) {
        if(e.getAction()==1)
        {
        Toast.makeText(getBaseContext(), "onDoubleTapEvent", Toast.LENGTH_LONG).show();
        }
        return true;
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
        if(e.getAction()==1)
        {
        Toast.makeText(getBaseContext(), "onSingleTapConfirmed", Toast.LENGTH_LONG).show();
        }
        return true;
    }

I also implemented the OnGestureListener methodes. But have no effect. Please help.

Upvotes: 4

Views: 5913

Answers (1)

MikeIsrael
MikeIsrael

Reputation: 2889

Where do you set the doubletap listener? Try adding this to your oncreate and see if it fixes the issue

GestureDetector detector = new GestureDetector(this, this);

Upvotes: 3

Related Questions