如果gestureDetector操作发生,如何禁用onListItemClick()操作

时间:2012-02-29 09:39:14

标签: android ontouchevent gesture-recognition ontouchlistener

我已阅读帖子:Fling gesture detection on grid layout并实施了手势检测。但我有以下问题。执行 onFling()操作后, onListItemClick()正在调用。如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

你可以尝试

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
   view.requestDisallowInterceptTouchEvent(true);
   .....
   view.requestDisallowInterceptTouchEvent(false);
}

也许有帮助

答案 1 :(得分:0)

问题出在 onFling()方法中。如果操作成功完成,则此方法应返回true ,否则调用onClickItemClicked()

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2,
        float velocityX, float velocityY) {
    if (e2.getAction()!=MotionEvent.ACTION_UP){

        return false;
    }

    try {
        float diffAbs = Math.abs(e1.getY() - e2.getY());
        float diff = e1.getX() - e2.getX();

        if (diffAbs > SWIPE_MAX_OFF_PATH)
            return false;

        // Left swipe
        if (diff > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            listener.onLeftSwipe();

            // Right swipe
        } else if (-diff > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            listener.onRightSwipe();
        }
        return true;
    } catch (Exception e) {
    }
    return false;
}