How to detect android double tap? [duplicate]

倾然丶 夕夏残阳落幕 提交于 2019-12-21 21:43:12

问题


How to detect the double tap in android? I implement OnDoubleTapListener and wrote this:

public boolean onDoubleTapEvent(MotionEvent e) {
        // TODO Auto-generated method stub
        if(e.getAction() == 1){
            Toast.makeText(getApplicationContext(),"Double Tap", Toast.LENGTH_SHORT).show();
        }
        return true;
    }

But it is not working. What is the wrong with this?


回答1:


public class GestureDoubleTap extends GestureDetector.SimpleOnGestureListener {

    @Override
    public boolean onDoubleTap(MotionEvent e) {
        //some logic
        return true;
    }

}

GestureDoubleTap gestureDoubleTap = new GestureDoubleTap();
gestureDetector = new GestureDetector(this/* context */, gestureDoubleTap);

view.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        return gestureDetector.onTouchEvent(motionEvent);
    }

});


来源:https://stackoverflow.com/questions/20941959/how-to-detect-android-double-tap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!