首先调用单击确认的原因而不是双击?

时间:2018-04-11 15:00:39

标签: android ontouchevent

实际上,我尝试使用singleTapConfirmed()doubleTap()执行两项操作。为此,我使用GestureTap类,其范围从GestureDetector.SimpleOnGestureListener开始。虽然它可以在某些设备上运行良好,但在某些设备中,例如nougatoreo,它首先接收singleTapConfirmed()即使是 doubleTap 。我想知道如何解决这个问题。

代码:

class GestureTap extends GestureDetector.SimpleOnGestureListener {
    private Context ctx;
        public GestureTap(Context ctx) {
            this.ctx = ctx;
    }


    @Override
    public boolean onDoubleTap(MotionEvent e) {
       Toast.makeText(ctx, ”Double Tap”, Toast.LENGTH_SHORT).show();
        return true;
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
     Toast.makeText(ctx, ”Single Tap”, Toast.LENGTH_SHORT).show();
        return true;
    }
}

1 个答案:

答案 0 :(得分:1)

这可能对您有帮助,

@Override
    public boolean onTouchEvent(MotionEvent event) {
        int action = event.getActionMasked();
                if (action == MotionEvent.ACTION_DOWN) {
                    final long now = event.getEventTime();
                    if (now - mTouchTime < ViewConfiguration.getDoubleTapTimeout()) {
                        mTouchTime = 0;
                        //doubleClick(event);
                    } else {
                        mTouchTime = now;
                    }
                } else if (action == MotionEvent.ACTION_POINTER_DOWN) {
                    mTouchTime = 0; // no double-tap for other fingers
                }

            return true;
    }