Android双击两次点火

use*_*687 2 android touch gestures

我使用了以下双击代码

setOnTouchListener(this);
detector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
    @Override
    public boolean onDoubleTapEvent(MotionEvent ev) {
        int x = (int)ev.getX();
        int y = (int)ev.getY();
        Toast.makeText(getContext(), "Double tapped", Toast.LENGTH_LONG).show();
    }
});
Run Code Online (Sandbox Code Playgroud)

我跑的时候跑两次吐司

有任何想法吗?

在KitKat 4.4上运行

任何帮助赞赏

标记

小智 11

这可能是因为onDoubleTapEvent通知down,move和up事件.在您的情况下,您有上下事件,导致toast显示两次.如果您只想验证是否已成功检测到双击,则可以使用onDoubleTap(MotionEvent e)而不是onDoubleTapEvent(MotionEvent ev).