views:

2431

answers:

3

How do you make those standard header labels in the ListView Control?

An example would be in the contacts application you see the first letter of the grouped contacts for each letter in the alphabet.

If possible please provide some code snippets on how to construct the grouped data and the display of the ListView.

+5  A: 

You can use my MergeAdapter, or my SectionedAdapter, or Jeff Sharkey's SeparatedListAdapter for that.

In the case of MergeAdapter, you would add an ordinary View (e.g., TextView) for a section header, then an Adapter for the contents of that section. Lather, rinse, repeat.

CommonsWare
Is this the standard methodology that google used in their applications? I saw that there were some custom implementations but it seemed like this type of work would have been integrated into the API at this point. Most custom implementations I saw were for Android 0.9.
Jeremy Edwards
"Is this the standard methodology that google used in their applications?" I have no idea. You would have to look at their source code on http://source.android.com. "but it seemed like this type of work would have been integrated into the API at this point" Outside of the preference system, there is nothing built into Android that provides an API for having section headings. Jeff Sharkey's implementation was originally for 0.9 but probably still works; my two implementations work up through 2.0.1.
CommonsWare
A: 

These solutions are not what I'm looking for, lists are still a bit laggy when you scroll down / up.

Nobody knows how the google calendar widget can be so fast and unlaggy ? I really wonder ...

Random
A: 

It should be noted that except for the MergeAdapter by @CommonsWare the samples are GPLed code.

@Random one thing I've found is that using ListViews with database cursors is somewhat slow. To resolve the issue I've added a list to my Adapter that caches container objects in memory so I can reduce how many times I am interacting with the database cursor.

This has helped speed up my list views once the data has been loaded into memory.

csaunders