0

Is it possible to set a ListFragment to not scroll using the getListView() method?

getListView().setScrollContainer(false); doesn't work.

Edit:

Weird behavior. This was supposed to block the List, but somehow you can still scroll it slowly if you keep touching it repeatedly.

scrollView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            return isBlockedScrollView;
        }
    });
Machado
  • 14,105
  • 13
  • 56
  • 97
  • you can extend the listview like it is done with scrollview in this answer http://stackoverflow.com/a/5763815/1659629 – Vladyslav Matviienko Jun 30 '15 at 12:37
  • I think the behavior of a ListFragment is a little bit different – Machado Jun 30 '15 at 13:29
  • Yes, but you don't have to use ListFragment. You can use regular Fragment and ListView in it. Anyway the answer on the link can solve your problem. The only thing missing is your will to fix it. – Vladyslav Matviienko Jun 30 '15 at 18:27
  • `Yes, but you don't have to use ListFragment.`What if I **must** use a ListFragment? I'm working on a situation where I can't simply change it to a Fragment, it would demand *a lot* of work. I have managed to find a solution, but it doesn't work **only** when you have clickable Views inside. Where's my lack of will? I'm working on finding a far, far more simple solution. – Machado Jun 30 '15 at 19:43

1 Answers1

0

If you ever need to disable the ListFragment scroll (which is different from regular ListView), a solution can be achieved by using this method inside onCreate:

getListView().setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {

                view.smoothScrollBy(0,0);
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

                view.smoothScrollBy(0,0);
            }
        });

If you want to set it temporarily, it's just a matter of adding conditions that will supply your needs.

Machado
  • 14,105
  • 13
  • 56
  • 97