Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ListView Headers

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.

like image 923
Jeremy Edwards Avatar asked Dec 27 '09 19:12

Jeremy Edwards


People also ask

How to set header in ListView Android?

This example demonstrates How to add header item for Listview in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.


1 Answers

You can use my MergeAdapter 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.

like image 153
CommonsWare Avatar answered Oct 11 '22 14:10

CommonsWare