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/commonsguy http://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

