Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Header in ListView in android

I need add header in my listview and header should always displayed even scrolling list.

Is it possible in android list view?

like image 389
Nandlal Virani Avatar asked Sep 22 '11 12:09

Nandlal Virani


2 Answers

The solution that works for me is to create a TableLayout that has a row with the heading and a row with the list like this:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

   <include layout="@layout/header" />

   <ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</TableLayout>

Please make sure that the ListView has @android:id/list as the ID.

like image 57
Henrique Rocha Avatar answered Sep 17 '22 20:09

Henrique Rocha


you can add header in list view like this:

View headerView = ((LayoutInflater)Activity.this.getSystemService(Activity.this.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.header, null, false);
list.addHeaderView(headerView)
like image 30
Vineet Shukla Avatar answered Sep 17 '22 20:09

Vineet Shukla