views:

105

answers:

1

Here is my layout.

For some reason the empty view (TextView in this case) always appears, even when the List is not empty. I thought the ListView would automatically detect when to show the empty view.

How can I hook up the empty view properly?

<RelativeLayout android:id="@+id/LinearLayoutAR"
            android:layout_height="fill_parent" android:layout_width="fill_parent">
            <ListView android:layout_width="fill_parent"
                android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/ARListView"></ListView>
            <ProgressBar android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:id="@+id/arProgressBar"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"></ProgressBar>
            <!-- Here is the view to show if the list is emtpy -->
            <TextView android:id="@id/android:empty" android:layout_width="match_parent"
        android:layout_height="match_parent" android:text="No Results" />
        </RelativeLayout>
+1  A: 

it should be

 <TextView android:id="@id/android:empty" android:layout_width="match_parent"
            android:layout_height="match_parent" android:text="No Results" />

take a close look at the id attribute

schwiz
I changed the XML to the following, but still I get the same results
Sheehan Alam
you have to be using a ListViewActivity for it to work this way.
schwiz
oh I see, my ListView is actually inside of a ViewFlipper. Is there another way I can present the view when the list is empty?
Sheehan Alam
you have implement the logic yourself, take a look at the sourcecode for ListViewActivity to see how they do it, or when you make your query check to see if it is empty, if so set your text view to VISIBLE, otherwise set it to GONE
schwiz