In an Android ListActivity, I am adding a button as a footer in a ListView. How can I apply layout formatting to this button like centering it and/or width=fill_parent?
I have tried a few things such as using setLayoutParams(), but have not gotten it to work - the footer always disappears when I try anything.
Here is the basic code I am working with
closeButton = new Button(this);
closeButton.setText(getResources().getString(R.string.title_closeprocess));
closeButton.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
closeProcess();
}
});
getListView().addFooterView(closeButton);
*update
Based on Christopher's answer, here is the footer view that I am adding to my listview, and the activity code that adds it to the listview:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/closebutton_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toptable"
android:layout_width="fill_parent"
android:stretchColumns="*"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content">
<TableRow>
<Button android:id="@+id/closebutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Skip Question"
android:gravity="center"
android:paddingTop="16dip">
</Button>
</TableRow>
</TableLayout>
</RelativeLayout>
ListView listView = getListView();
closeButtonView = getLayoutInflater().inflate(R.layout.closebutton_layout, listView, false);
closeButton = (Button)closeButtonView.findViewById(R.id.closebutton);
closeButton.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
closeQuestion();
}
});
listView.addFooterView(closeButtonView);