Hi Mark.

I've taken a look at this, and put together a quick sample based on
your demo.

It seems to me that you must have your list content already separated
before adding them to the ListView. So, you add one Array, then you
add a different View, then you add another Array.

I can probably find a way to sort my data in this way, although I was
hoping to add the view on the fly. My data is currently returned as
one long List, and I don't know in advance where these separator views
are going to go. I need to study the contents of my data as it's added
to the View, and say "Ah, here's some condition, add a separator view
here". Does that make sense, and can this be done?

Thanks.

On Nov 11, 12:26 pm, Mark Murphy <[email protected]> wrote:
> On Thu, Nov 11, 2010 at 7:20 AM,Neilz<[email protected]> wrote:
> > Hi all. I have created a ListView from a collection of objects, using
> > an ArrayAdaptor to set the items.
>
> > The objects used to populate the list have a NAME field, and are
> > sorted into alphabetical order, so ultimately the ListView is long
> > list of names.
>
> > I now want to make the list more user friendly. I'd like to add a
> > separator for each letter of the alphabet, saying "A", "B" etc. The
> > separator could be one of the list items (non-clickable) or just a
> > normal View.
>
> > I'm just not sure how I can manipulate the ListView to achieve this,
> > and would appreciate any help.
>
> It's not a question of the ListView, but of the ListAdapter. Your
> ListAdapter needs to:
>
> -- Override getViewTypeCount() to return 2
> -- Override getItemViewType() to return 0 for regular rows and 1 for headings
> -- Override getView() (or newView() and bindView() for CursorAdapter)
> and have it properly create the right rows and bind them
>
> This is somewhat of a pain.
>
> I have a MergeAdapter that can simplify it, but only where each
> section is its own adapter, with plain Views being interspersed:
>
> https://github.com/commonsguy/cwac-merge
>
> Creating a HeaderCursorAdapter that injects headings based on some
> rule (e.g., when the first letter of such-and-so column in the Cursor
> changes) is on my list of 18,000 things to do. Though anyone is
> welcome to go and beat me to writing it. :-)
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> Android App Developer Books:http://commonsware.com/books

-- 
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

Reply via email to