4

我需要在双击屏幕上烤点东西。我尝试了以下代码。但它不起作用。双击没有吐司。这些代码有什么问题?

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;
    }

我还实现了 OnGestureListener 方法。但是没有效果。请帮忙。

4

1 回答 1

3

你在哪里设置双击监听器?尝试将此添加到您的 oncreate 中,看看它是否可以解决问题

GestureDetector detector = new GestureDetector(this, this);
于 2012-05-22T10:00:19.130 回答