java.lang.Object | |||||
↳ | android.content.Context | ||||
↳ | android.content.ContextWrapper | ||||
↳ | android.view.ContextThemeWrapper | ||||
↳ | android.app.Activity | ||||
↳ | android.app.ListActivity |
![]() |
Class Overview
ListActivity显示一个绑定到数组或游标这些数据源的一个列表,并且列表的每一项提供一个点击事件的管理方法,当用户点击其中的列表项的时候就能进行相应的处理。
ListActivity容纳了一个ListView对象,这个对象能够被绑定到不同的数据源,一般是一个数组或者存储了一组查询结果的游标。
屏幕布局
ListActivity的默认布局由一个位于屏幕中心的全屏列表构成。但是,如果你不想使用默认的布局,可以在onCreate()方法中通过setContentView()方法设定你自己定制的布局。
如果指定你自己定制的布局,你的布局中必须包含一个id为"@android:id/list"(如果是使用代码的形式,则是 list)的ListView 。此外,你自定义的view为空时,能够包含另外一个任何类型的view对象。
"empty list"notifier必须有一个id"android:empty"。要注意的是:Note that when an empty view is present, the list view will be hidden when there is no data to display.
下面的代码示例一个丑陋的自定义屏幕布局。这个布局有一个list,这个list有绿色的背景色,还有一个用来代替的红色的“no data”消息。
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingLeft="8dp"
- android:paddingRight="8dp">
- <ListView android:id="@id/android:list"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="#00FF00"
- android:layout_weight="1"
- android:drawSelectorOnTop="false"/>
- <TextView id="@id/android:empty"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="#FF0000"
- android:text="No data"/>
- </LinearLayout>
转载于:https://blog.51cto.com/255135/807055