How to show a button at the end of an Android ListView

Solution 1:

You may want to use ListView#addFooterView() to add a View at the bottom of the ListView.

Solution 2:

I do it like this fixed button at the buttom of the screen

   <RelativeLayout
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/listView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/btn_New" >
    </ListView>

    <Button
        android:id="@+id/btn_New"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_marginBottom="20dp"
        android:text="@string/New"
        android:width="170dp"
        android:layout_alignParentBottom="true" />
</RelativeLayout>

if ur using linearLayout then assign android:layout_weight="1" to the listview and dont assign weight for button it works

Solution 3:

You could do something like this:

final Button btnAddMore = new Button(this);
btnAddMore.setText(R.string.art_btn_moreIssues);
exArticlesList = (ExpandableListView) this.findViewById(R.id.art_list_exlist);
exArticlesList.addFooterView(btnAddMore);

Solution 4:

1 If you want to add Button as the last element of the list view

You must create custom ListAdapter for your ListView which will create a view with a Button in the getView method. You should decide how to return your custom view for the last element, you can hardcode it (return element count +1 in getCount method and return custom view in getView when position > element count) or you can add element to the structure you will be taking data from (Array, Cursor etc.) and check if field of element have certain value

2 If you want to add element below list view

You should use android:layout_width attribute and make ListView and "empty" TextView (you should use it to show users that list is empty and View rendering is completed) layout_weight greater than buttons layout_weight

Check how it's done in Transdroids search Activity http://code.google.com/p/transdroid/source/browse/trunk/res/layout/search.xml