Android: How to add static header to the top of a ListActivity

I wanted to add static header to my ListView and here how I done it.

In my ListActivity Class.

@Override
 protected void onCreate(Bundle savedInstanceState) {
  
  super.onCreate(savedInstanceState);
  
  
  
  ListView listView = getListView();
  LayoutInflater inflater = getLayoutInflater();
  ViewGroup header = 
(ViewGroup)inflater.inflate(R.layout.header, lv, false);
  listView.addHeaderView(header, null, false);

  String[] values = getResources().getStringArray(R.array.reg_dates);
  
  ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, values);
  setListAdapter(adapter);
  
 }

And here is my header.xml file.

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


    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Enable Reminder" />

 </LinearLayout>

Comments

Popular posts from this blog

Offers on Friday, April 24, 2020

Fatal: LoadModule: error loading module 'mod_sql_mysql.c'