0

I am trying to place a Button at the bottom of a ListActivity. The following works perfectly in the Eclipse designer but not when I launch the app of my phone or AVD.

Any ideas?

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

    <ListView
        android:id="@+id/list"
        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:text="Button"
        android:layout_alignParentBottom="true" />
</RelativeLayout>

Button appears correctly in the designer Button appears correctly in the designer

Button not appearing on my phone or AVD Button not appearing on my phone or AVD

Cathal Coffey
  • 1,105
  • 2
  • 20
  • 35

3 Answers3

0

you have to put the button BEFORE the list:

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

<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:text="Button"
    android:layout_alignParentBottom="true" />

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

so the layout inflater can 'see' which view the list have to be on top of

Budius
  • 39,391
  • 16
  • 102
  • 144
  • This had no effect. The Button still shows in the Eclipse designer but not on my phone or AVD. And yes I made sure to uninstall the app from the phone and AVD to verify the modification actually took place. – Cathal Coffey Oct 28 '12 at 14:16
0

you may add a footer to your ListView. you can use the example provided in this link

View footerView = ((LayoutInflater)      
ActivityContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);
ListView.addFooterView(footerView);
Community
  • 1
  • 1
MKB
  • 7,587
  • 9
  • 45
  • 71
0

this one is completely my mistake. My Activity was extending SherlockListActivity, instead of SherlockActivity. So of course the Button wasn't displaying.

Thanks for all your help, Cathal

Cathal Coffey
  • 1,105
  • 2
  • 20
  • 35