WayWay WayWay - 27 days ago 7
Android Question

Android ListView with section headers in a grouped table format similar to iOS UITableView

I have a ListView but I would like to incorporate section headers into the list view.

However, how would I create these section headers? Through xml?

Additionally, I would also like for them to stick to the top of the ListView until the user scrolls into the next section.

A really good example of such implementation can be found in the default People app which is bundled with Android.

This is what I have for my list view:

<?xml version="1.0" encoding="utf-8"?>
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"

< ListView
android:id="@+id/homework_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"/ >

< /LinearLayout>

Answer

There is no way to do this in xml, you can use something like: https://github.com/emilsjolander/StickyListHeaders