Android 朝花夕拾: ListActivity
ListActivity:
google新增的widget. 默认情况下,它的layout里面只有一个ListView,且居中填满parent.
使用它时,如果需要自定义layout, 则在layout中,必须要有ListView且 ID 为系统ID; @id/android:list
如果配合 一个TextView使用,把他们放在同一个LinearLayout中,且TextView的ID为系统的:@id/android:empty ;当list中item个数为0的时候, 则显示TextView的内容.(例如显示:没有数据);
1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout
3 xmlns:android="http://schemas.android.com/apk/res/android"
4 android:layout_width="match_parent"
5 android:layout_height="match_parent">
6
7 <ListView android:layout_width="fill_parent"
8 android:layout_height="fill_parent"
9 android:id="@id/android:list"
10 ></ListView>
11
12 <TextView android:layout_width="fill_parent"
13 android:layout_height="fill_parent"
14 android:text="@string/data_empty"
15 android:id="@id/android:empty"></TextView>
16 </LinearLayout>
3 xmlns:android="http://schemas.android.com/apk/res/android"
4 android:layout_width="match_parent"
5 android:layout_height="match_parent">
6
7 <ListView android:layout_width="fill_parent"
8 android:layout_height="fill_parent"
9 android:id="@id/android:list"
10 ></ListView>
11
12 <TextView android:layout_width="fill_parent"
13 android:layout_height="fill_parent"
14 android:text="@string/data_empty"
15 android:id="@id/android:empty"></TextView>
16 </LinearLayout>