Android双击两次点火

时间:2015-01-23 00:30:35

标签: 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();
    }
});

当我跑步时,跑两次烤面包

有什么想法吗?

在KitKat 4.4上运行

任何帮助表示赞赏

标记

1 个答案:

答案 0 :(得分:10)

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

相关问题