Question

I have read the post: Fling gesture detection on grid layout and implemented gesture detection. But I have the follow problem. After the action onFling() occurred, the onListItemClick() is calling. How to fix this problem?

Was it helpful?

Solution 2

The problem was in the onFling() method. This method should return true if operation completed successfully, otherwise calls 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;
}

OTHER TIPS

You can try

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

Maybe helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top