views:

66

answers:

1

There is something I'm just not getting, and I'm looking for assistance in understanding what is happening here.

I have a custom list adapter (that just extends BaseAdapter) that I have successfully been using to generate and display a list. Now I want to add a static footer to the bottom of my list. After looking at a number of resources (specifically this one) I've come to realize that my reluctance of using XML has to come to an end, and set up the following xml layout in a file called devices_list.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout android:id="@+id/bottom_control_bar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true">
    <ToggleButton android:id="@+id/bottom_control_toggle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:textOff="Filter Favourites OFF" 
        android:textOn="Filter Favourites ON"/>
</LinearLayout>
<ListView android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="0dip" 
    android:layout_above="@id/bottom_control_bar">
</ListView>
<TextView android:id="@android:id/empty" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:text="@string/main_empty_list"
    android:layout_above="@id/bottom_control_bar"/>
  </RelativeLayout>

After some adjustments to the activity that holds the list, I ran the code. I see my footer, (and also the tab widget which is parent to everything), but the area where the list goes is empty.

    @Override
    public void onCreate(Bundle savedInstanceState){
       super.onCreate(savedInstanceState);
       this.setContentView(R.layout.devices_list);

       db = new DbManager(this);
       db.open();

       AllCur = db.fetchAllDevices();
       startManagingCursor(AllCur);

       list = new DeviceListAdapter(this, AllCur);   //make my custom list adapter                  
       setListAdapter(list);
            }

Is there some way to link up the ListView widget declared in my xml with my DeviceListAdapter? It's pretty clear to me now that I'm not entirely sure about how this is all working. Any help in clarification would be much appreciated.

+1  A: 

You have both the ListView and the TextView set to android:layout_above="@id/bottom_control_bar", which means the TextView will overlap the ListView. And, you have said that your ListView height is 0dip, which will make for an extremely short list.

I would define the ListView as being above the TextView and anchored to the top of the screen (android:layout_alignParentTop="true").

Is there some way to link up the ListView widget declared in my xml with my DeviceListAdapter?

You already are, by calling setListAdapter().

CommonsWare
aha! The android:layout_alignParentTop="true" is what did it. I went back to my example, surprised that I missed that, and realized it was never there. I think it is because the example I followed places the list between a header and a footer, while I am simply placing mine above a footer. The height of the ListView doesn't seem to matter once the alignment to the parent is set.
Aurora