How can I get my ListView to scroll? How can I get my ListView to scroll? android android

How can I get my ListView to scroll?


Instead of ListView with other layouts inside ScrollView create one ListView with header and footer.

Add views that should be above ListView as a header:

addHeaderView(View v)

and that below as a footer:

addFooterView(View v)

Put everything what should be above ListView to header of ListView and the same with footer.

    LayoutInflater inflater = LayoutInflater.from(this);    mTop    = inflater.inflate(R.layout.view_top, null);    mBottom = inflater.inflate(R.layout.view_bottom, null);    list.addHeaderView(mTop);    list.addFooterView(mBottom);    // add header and footer before setting adapter    list.setAdapter(mAdapter);

In result you'll get one scrollable view.


Actually, the way that I have it set up is really working... Placing a ListView in a LinearLayout within a ScrollView. Just avoid that the ListView is the direct child of the ScrollView, and it will work out just fine...

Just be aware that if there aren't enough items in the ListView to fill it so it goes 'off screen', that it won't scroll (kind of logically though). Also note that when you have enough items to scroll through, you need to keep pressing on an item in the ListView to make it scroll, and half of the time, focus is given to the global scrollview in stead of the ListView... To avoid this (most of the time), keep pressing on the most top or most down item, depending on which way you want to scroll.This will optimize your chance to get focus on your ListView.

I've made a video that it is possible, am uploading it now to YouTube...

Video is http://www.youtube.com/watch?v=c53oIg_3lKY. The quality is kinda bad, but it proves my point.

Just for a global overview, I used the ScrollView to be able to scroll my entire activity, the LinearLayout for the Activity's layout, and the ListView to, well, make the list...


Try this code may help you

        ListView listView = ( ListView ) findViewById(R.id.lsvButton3);        listView.setOnTouchListener(new ListView.OnTouchListener() {            @Override            public boolean onTouch(View v, MotionEvent event) {                int action = event.getAction();                switch (action) {                    case MotionEvent.ACTION_DOWN:                        // Disallow ScrollView to intercept touch events.                        v.getParent().requestDisallowInterceptTouchEvent(true);                        break;                    case MotionEvent.ACTION_UP:                        // Allow ScrollView to intercept touch events.                        v.getParent().requestDisallowInterceptTouchEvent(false);                        break;                }                // Handle ListView touch events.                v.onTouchEvent(event);                return true;            }        });