I have a list view and depending on some logic I want to temporary disable the scrolling. view.setOnScrollListener(null); doesn't helps me I guess I need to write some code, can someone give me a hist or some snippet ?
Thanks
You can make the ListView widget never scrollable by setting physics property to NeverScrollableScrollPhysics().
You can provide physics: NeverScrollableScrollPhysics() on GridView to disable scroll effect. If you want scrollable as secondary widget use primary: false, To have Full Page scrollable, you can use body:SingleChildScrollView(..) or better using body:CustomScrollView(..) Save this answer.
You can use the following code in your singleChildScrollView. physics: NeverScrollableScrollPhysics(), It stops it from being able to scroll.
Another option without creating a new custom ListView would be to attach an onTouchListener
to your ListView and return true in the onTouch()
callback if the motion event action is ACTION_MOVE
.
listView.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { return (event.getAction() == MotionEvent.ACTION_MOVE); } });
In your CustomListView:
@Override public boolean dispatchTouchEvent(MotionEvent ev){ if(ev.getAction()==MotionEvent.ACTION_MOVE) return true; return super.dispatchTouchEvent(ev); }
Then ListView will react to clicks, but will not change scroll position.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With