[TUT] ListView with a Footer Item

Just figured this one out myself.

If you want a ListView with a button / edittext or other view item below the ListView that stays at the bottom of the screen while the view still scroll’s:

 

listview with footer item

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dip"
  >
  <LinearLayout
    android:id="@+id/bottom_view"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true">
      <!--Put whatever view item you want here -->
     <EditText
       android:id="@+id/conversation_reply"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:text="write a reply..."
     />
  </LinearLayout>
  <ListView
    android:id="@+id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:cacheColorHint="#00000000"
    android:layout_above="@id/bottom_view" />
</RelativeLayout>

Notice how the footer linearlayout is in the XML above the listview, this is so you can reference it in the ListView.

You can then use the Android Dev tutorial for implementing your listview:
http://developer.android.com/resources/tutorials/views/hello-listview.html
Or this custom listview tut I found really helpful (more screenshots):
http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/

Please say thanks if your using this, as it encourages me to do more :-)

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

4 thoughts on “[TUT] ListView with a Footer Item