0

I have a RecyclerView which I want to be scrolled only programmatically with smoothScrollToPosition command and not from user swipe events. I tried all the solutions from this post without success.

Any suggestions on how to solve this problem?

Student
  • 1,986
  • 5
  • 19
  • 35

1 Answers1

1

I didn't yet try it but I think overriding the onTouch will do the trick. You could do:

mRecyclerview.setOnTouchLisntener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

These methods will consume the touch event while doing nothing with it.

EDIT: Noticed you need to keep the click functionality:

mRecyclerview.setOnTouchLisntener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    return true;
                case MotionEvent.ACTION_UP:
                    return false;
                case MotionEvent.ACTION_MOVE:
                    return true;
            }
            return false;
        }
    });
Alex Newman
  • 1,341
  • 11
  • 31