Search code examples
androidlistviewscrolllistener

Disable scrolling in listview


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


Solution

  • 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.