[UPDATE]
I solve the problem by adding addHeaderView :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
You would do that the same way as you would add headings in any other ListView
, by teaching your ListAdapter
to return heading rows as well as detail rows. At the low level, this involves overriding methods like getViewTypeCount()
and getItemViewType()
in your ListAdapter
, plus having getView()
know the difference between the row types. Or, use an existing high-level implementation like https://github.com/emilsjolander/StickyListHeaders or http://code.google.com/p/android-amazing-listview/ or any of the others found when searching for android listview headers
.
Maybe it's a bit late but I think I have a simpler solution. In your Activity's layout, instead of adding a listView inside the DrawerLayout, you can add for example a LinearLayout, and you can easily add separators and rows. For example:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.astuetz.viewpager.extensions.PagerSlidingTabStrip
android:id="@+id/indicator"
android:layout_height="48dip"
android:layout_width="fill_parent"/>
<ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Separator 1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First button"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Separator 2"/>
</LinearLayout>
And in the Activity, you can add the listeners to the buttons.
Hope that helps!
Put a TextView
above a ListView
, and wrap it inside a vertical LinearLayout
. Give to your ListView android:layout_weight="1"
and android:layout_height="0dip"