3

I have a ListView inside ScrollView. I can enable scroll of ListView by

listView.getParent().requestDisallowInterCeptTouchEvent(true);

But the problem is when i scroll up in listView and it reaches top it should scroll to parent view i.e. parent scroll has to work . How can i do this ? any suggestion please.

Gopal Gopi
  • 11,101
  • 1
  • 30
  • 43
prabhu
  • 1,158
  • 1
  • 12
  • 27
  • http://stackoverflow.com/questions/15062365/how-to-work-when-listview-inside-the-scrollview try this – june Mar 21 '14 at 12:33
  • Possible duplicate of [Disable scrolling of a ListView contained within a ScrollView](http://stackoverflow.com/questions/12212890/disable-scrolling-of-a-listview-contained-within-a-scrollview) – Edward Brey Aug 08 '16 at 16:25

3 Answers3

6
listView.setOnTouchListener(new OnTouchListener() {

    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_MOVE) {
            return true; // Indicates that this has been handled by you and will not be forwarded further.
        }
        return false;
    }
});

OR

To make the View unselectable just get the view and .setClickable(false)

OR

listView.setScrollContainer(false);
Kanaiya Katarmal
  • 5,974
  • 4
  • 30
  • 56
4

You can override ScrollView class and insert these methods inside:

private boolean isScrollEnabled = true;

public void enableScroll(boolean isScrollEnabled ) {
    this.isScrollEnabled = isScrollEnabled ;
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (isScrollEnabled) {
        return super.onInterceptTouchEvent(ev);
    } else {
        return false;
    }
}

This is the cleanest solution to achieve this. You only call scrollView.enableScroll(true) to enable scrolling or scrollView.enableScroll(false) to disable it.

Gaskoin
  • 2,469
  • 13
  • 22
1

I would suggest to embed your upper view i.e any viewgroup above list view into listview header. ListView has a method, listview.addHeaderView(). That way you would be able to scroll your list (Whole View) even on small size display and you don't need scrollview.

Shah
  • 661
  • 2
  • 9
  • 19