2

Here is my problem, I have a RecyclerView which I must handle both long press and scroll and move events. Basically I want to intercept the long press when user scrolls. And when the long press occured I want to intercept scrolling but continue to do some actions on ACTION_MOVE after long pressed. This is what I have so far

recyclerView.setOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
        @Override
        public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent ev) {

            final int action = MotionEventCompat.getActionMasked(ev);

            if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
                // Release the scroll.
                mIsScrolling = false;
                gestureDetectorCompat.onTouchEvent(ev);
                return false;
            }

            if(action == MotionEvent.ACTION_MOVE) {
            // when user scrolls it comes here
            return true; // to handle scroll on onTouchEvent
            }
        }

        public void onRequestDisallowInterceptTouchEvent(boolean disallow) {
        }

        @Override
        public void onTouchEvent(RecyclerView rv, MotionEvent e) {
             //never comes here after return true onInterceptTouchEvent
        }

    });

initializing gestureDetectorCompat

gestureDetectorCompat = new GestureDetectorCompat(context,getOnGestureListener());

public GestureDetector.SimpleOnGestureListener getOnGestureListener() {

    return new GestureDetector.SimpleOnGestureListener(){

        @Override
        public void onLongPress(MotionEvent e) {
             if(!mIsScrolling)
             //do something
        }

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            mIsScrolling = true;
            return true;
        }
    };
}

this topics I checked so far but didn't help in my case with recycler view

Move Events AFTER LongPress

Android long press with scroll

Thank you for your helps.

Community
  • 1
  • 1
  • do you have found solution ? – waki Feb 01 '16 at 06:47
  • Yes. onInterceptTouchEvent method, decide what action type you should intercept (MotionEvent.ACTION_MOVE in my case) end return true for that case. Then handle it in onTouchEvent method – Mert Kılıç Feb 08 '16 at 07:57

0 Answers0