I have a ListActivity with custom rows, icons, TextViews, etc. So I am not using the XML ListView resource. I do have a scrolling list from an Array, and a header on top. I just want the header not to scroll and be persistent on the screen. Here is my code:
ListDisplay.java
View header = getLayoutInflater().inflate(R.layout.header, null, false);
ListView listView = getListView();
listView.addHeaderView(header, null, false);
setListAdapter(new MyArrayAdapter(this, names));
header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#008800"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="15dp"
android:clickable="false"
android:text="n/a"
android:textColor="#fff"
android:textSize="25dp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:clickable="false"
android:text="n/a"
android:textColor="#fff"
android:textSize="12dp" />
</TextView>
</LinearLayout>
rowlayout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/list_selector" >
<ImageView
android:id="@+id/icon"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginTop="15dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:src="@drawable/tv" >
</ImageView>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginTop="14dp"
android:text="@+id/label"
android:textColor="#000"
android:textSize="23dp" >
</TextView>
</LinearLayout>
I don’t think I need to display the ArrayAdapter Java code?
Create a layout that will include header view and list view.
ListViewitems should be set up usingAdapter. There are quite a few tutorials on the subject found on the web such as this one