Add Many Sections In An Android ListView

I have seen custom code made by fellow Android developers on creating a ListView widget much like the one you see in the Contacts app. However, I wanted my ListView to display more than 1 section just like in the image above (click to enlarge).

The simplest adapter I found is Commonware’s called SectionedAdapter. However, it caters to only 1 header per set so I modified his existing code to cater adding a header without any items within it.

Just do it like this

I also added an extra parameter to the addSection() method in case you want to have a different background color. Just do it like this

And here is the full source of my modified class of Commonware’s SectionedAdapter class.

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *