I've searched around for solutions to this problem, and the only answer I can find seems to be "don't put a ListView into a ScrollView". I have yet to see any real explanation for why though. The only reason I can seem to find is that Google doesn't think you should want to do that. Well I do, so I did.
So the question is, how can you place a ListView into a ScrollView without it collapsing to its minimum height?
This library is the easiest and quickest solution to the problem.
Insted of putting
ListView
inside aScrollView
, we can useListView
as aScrollView
. Things which has to be inListView
can be put inside theListView
. Other layouts on top and bottom ofListView
can be put by adding layouts to header and footer ofListView
. So the entireListView
will give you an experience of scrolling .This whole problem would just go away if LinearLayout had a setAdapter method, because then when you told someone to use it instead the alternative would be trivial.
If you actually want a scrolling ListView inside another scrolling view this won't help, but otherwise this will at least give you an idea.
You need to create a custom adapter to combine all the content you want to scroll over and set the ListView's adapter to that.
I don't have sample code handy, but if you want something like.
Then you need to create an adapter that represents all of that content. The ListView/Adapters are smart enough to handle different types as well, but you need to write the adapter yourself.
The android UI API just isn't as mature as pretty much everything else out there, so it doesn't have the same niceties as other platforms. Also, when doing something on android you need to be in an android (unix) mindset where you expect that to do anything you're probably going to have to assemble functionality of smaller parts and write a bunch of your own code to get it to work.