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.
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); ArrayAdapterAnd here is my header.xml file.adapter = new ArrayAdapter (this, android.R.layout.simple_list_item_1, values); setListAdapter(adapter); }
<?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
Post a Comment