Wednesday, June 23, 2010

RE: [android-developers] ListView Groups? Please

Mark,

Thank you for these links, I'll take a look and see if I can make it work on
my end.

-----Original Message-----
From: android-developers@googlegroups.com
[mailto:android-developers@googlegroups.com] On Behalf Of Mark Murphy
Sent: Wednesday, June 23, 2010 1:40 PM
To: android-developers@googlegroups.com
Subject: Re: [android-developers] ListView Groups? Please

On Wed, Jun 23, 2010 at 1:34 PM, Tommy <droidap@gmail.com> 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment