Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nesting ListView in ScrollView - A subtle clarification

Tags:

android

I've read many posts indicating how a ListView should not be nested within ScrollView.

I was wondering if this applies to all AdapterView's in general ?

It'd be helpful to know before finding out after writing a whole bunch of code for a custom list view that will be nested in a ScrollView. I want to base it on an AdapterView so that I can use it similarly to a standard ListView (to help minimize re-write of my current ListView related code).

Thank you.

like image 921
samus Avatar asked Jul 27 '26 11:07

samus


1 Answers

I was wondering if this applies to all AdapterView's in general ?

On the whole, ScrollView does not play nice with the other kids.

It'd be helpful to know before finding out after writing a whole bunch of code for a custom list view that will be nested in a ScrollView.

There is no need to put a ListView in a ScrollView. Just put the other stuff from the ScrollView into the ListView itself, either as header/footer views, or using my MergeAdapter, or similar techniques.

I want to base it on an AdapterView so that I can use it similarly to a standard ListView

Creating a custom AdapterView from scratch is not easy. If you look at the source for ListView, and its AbsListView immediate parent, there are several thousand lines of code. It would be much simpler to just put the contents of the ScrollView into the ListView, per my preceding paragraph.

like image 199
CommonsWare Avatar answered Jul 30 '26 08:07

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!