Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding headers to an Android listview

So I have a listview and I want to add different "sections" to it. I understand how addHeaderView works and it's straight forward, but is there a way to add section headers? Like let's say I have an alphabetical list, is there a way to mark the top of each section of letters? The list is dynamic though, so I won't know when/where I'll need a section header until I get to that point.

like image 963
Falmarri Avatar asked Jul 08 '10 17:07

Falmarri


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

These section headers are called "separators" in Android lists. To specify that given entry in the list is a separator, you must modify your Adapter to return false from isEnabled method for that position. It helps if you properly write the getItemViewType method, so you can have customized layout for separator entries.

like image 100
ognian Avatar answered Nov 02 '22 13:11

ognian