views:

349

answers:

2

I'm trying to tackle a problem that seemingly many Android developers have, which is how to intersperse lists with non-list data, in one big scrollable pane.

The model I have in mind is the screen for an individual app in the Market. You have a big description, a list of a few lazily loaded comments, and then some individual items that do different things, like visit the developer's web page, call them, etc. And then in between them all, are nice section headers.

Emulating this approach seems to be extremely hard. I've read enough SO answers and mailing list posts to know not to put a ListView inside of a ScrollView, but I want the same effect without using addHeader() and addFooter() with very complex header and footer views.

I've tried using a LinearLayout that I stock with views myself, but I can't get the pleasant click effects that default list items have (the orange background, white for long-click, etc.).

What do I do?

+3  A: 

Take a look at my MergeAdapter, which is designed to handle scenarios like this.

CommonsWare
I did look at your MergeAdapter while researching this, and at this point it's looking like the simplest thing to do. All the same, I'm dissatisfied that embedding multiple lists into a single scrollable view isn't far simpler. I get that in the current implementation of Android, ScrollViews and ListViews compete for scrolling mastery, but the implementation should change so that it's easier.If no one thinks of a simpler answer, I'm happy to mark your answer as accepted, as MergeAdapter is what I'll use (or some modification based on it).
Klondike
A: 

Mark's example would work. basically you need an adapter with different view types. Another nice example is http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09/ which might work better than Mark's because you want to have separators and group things together.

Alex Volovoy
If Jeff's pattern fits (and GPLv3 is acceptable as a license), his code is a fine solution.
CommonsWare