On Wed, Jun 23, 2010 at 1:34 PM, Tommy <[email protected]> wrote: > Is there a way to do groups in a listview? Like I have a list of > certain states, each state has its own sublist. I'd sort of like to > replicate the HTML optgroup/option setup where you have a parent group > then child groups. Is there a way to do this built in or would I have > to do something tricky with a custom view for Parent elements then > switch the view back to the child element style?
You have different rows return different View types, one for headings and one for the "main" rows. To do this, in addition to having the appropriate smarts in getView() or newView()/bindView() in your custom Adapter, you need to make sure you properly override getItemViewType() and getViewTypeCount(). You may also wish to deal with isItemEnabled() so people do not click on your headings if those are not meant to be clickable. Here is a reusable component that can wrap a lot of this up for some sorts of lists: http://github.com/commonsguy/cwac-merge And a sample project showing using it for section headings: http://github.com/commonsguy/cw-advandroid/tree/master/ListView/Sections/ -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy _The Busy Coder's Guide to *Advanced* Android Development_ Version 1.6 Available! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

