Falmarri
Falmarri

Reputation: 48569

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.

Upvotes: 6

Views: 3250

Answers (3)

Jarek Potiuk
Jarek Potiuk

Reputation: 20047

You can also use http://code.google.com/p/android-section-list/ - it solves exactly this problem and adds a nice feature taken from iOS - the section header stays on screen with transparency while you scroll the section down, so you see which section you are in....

Upvotes: 0

Kris
Kris

Reputation: 921

i tried this example and its working fine.

http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09/

it helped a lot for my task.

Upvotes: 0

ognian
ognian

Reputation: 11541

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.

Upvotes: 3

Related Questions