0

I create a listview and that listview has a header. I use addHeaderView() method. But when i scroll down in listview the scrollbar vanishes. Is there any way to avoid this i.e i want to show the header all the times, if scrolled still it will show.

Anky
  • 1
  • Same question: http://stackoverflow.com/questions/2620177/android-adding-static-header-to-the-top-of-a-listactivity – Finn Larsen Sep 21 '11 at 14:08
  • Have a look at the [post](http://blog.maxaller.name/2010/05/attaching-a-sticky-headerfooter-to-an-android-listview/) – Adil Soomro Sep 21 '11 at 14:40

2 Answers2

1

To do that you can't do that with the addHeaderView() method.

If you want to place a header on top you should place that in the layout, something like this.

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

    <TextView
        android:id="@+id/titleBarText"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:text="Title"/>

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

</LinearLayout>
Mats Hofman
  • 7,060
  • 6
  • 33
  • 48
0

The widget is behaving as intended. For what you need, you need to create a relativelayout with TextView at top followed by listview. The textview would act as the header and be static irrespective of your scroll.

PravinCG
  • 7,688
  • 3
  • 30
  • 55