If a listview is not given any items, how is it rendered? Will it still expand to fill the space in the layout allotted to it?
+3
A:
Yes, it will still fill the space, but instead of displaying a list you can have it display another view. Here's an example:
<FrameLayout
android:id="@+id/GLFrame"
android:layout_height="fill_parent"
android:layout_width="fill_parent" />
<TextView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@android:id/empty"
android:gravity="center_vertical|center_horizontal|center"
android:text="@string/no_songs_found"
android:textColor="#FFF"
android:textSize="20sp"
android:textStyle="bold" />
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/list"
android:cacheColorHint="#0000" />
The key here is the "@android:id/empty"
and "@android:id/list"
ids. These tells Android that it should either display the list or the other view if the list is empty.
CaseyB
2010-02-22 20:55:54
This only works if you are using `ListActivity`.
CommonsWare
2010-02-22 20:59:14
That is true. I forgot to mention that, thanks!
CaseyB
2010-02-22 21:43:22
BTW, if my main view layout contains a listview that is just *part* of the layout (i.e. there are other widgets above and below it), should I still extend ListView or should I enscapsulate that some other way?
Eno
2010-02-23 07:40:48
You can still use a ListActivity.
CaseyB
2010-02-23 14:24:44