3

enter image description here

I have been searching all day on how to make these sections in a ListView. Haven't found anything yet. I have been through many blogs and most of them talk about the approach CommonsWare takes (i.e. SectionAdapter) but the SectionAdapter.java is nowhere to be seen on his GitHub repo.

How can this be made? (i.e. the part marked A. I am not trying to make a Preferences list. Something more on the lines of a Contact List)

prometheuspk
  • 3,754
  • 11
  • 43
  • 58
  • [This](http://stackoverflow.com/questions/1013765/creating-categories-in-a-listview) answer has links to pretty nice examples. Did you check them? – denolk Feb 20 '12 at 11:53

2 Answers2

1

I struggled a lot on this. There are a number of ways to do this. The one I found simplest and which I recommend is using separator view in your list item layout (the one you inflate in get view) and change its visibility based on whether on not there should be a header. I use something like this:

<TextView
    android:id="@+id/separator"
    android:layout_width="fill_parent"
    android:visibility="gone"
    android:layout_height="wrap_content" />

I found this much simpler than the other adapter. I just kept track of where I wanted to have a separator using a variable and based on that I setVisibility(View.VISIBLE) in my getView().

Saad Farooq
  • 13,172
  • 10
  • 68
  • 94
0

Try putting this on the textview in the xml:

<TextView 
style="?android:attr/listSeparatorTextViewStyle"
android:id="@+id/tv_separator"
android:visibility="gone"
/>

this will make it like preferences categories that looks much better..

Aziz
  • 461
  • 7
  • 18