ListActivity是继承自Activity的一个子类,这个ListActivity可以用来展示一个列表数据其数据源可以绑定到一个数组或者是数据库游标。

在进行列表数据展示时可以直接让自己的Activity继承自ListActivity ,ListActivity 自己有一个默认持有一个ListView控件,也就是说你不用在LayOut布局文件中放置一个ListView 的配置节。
ListActivity 默认持有的这个ListView是一个全屏的居中显示的列表控件。在OnCreate 方法中不需要通过setContentView()来设置主界面的显示LayOut布局文件,也就是说在默认情况下是 不需要一个XML文件来作为ListActivity的界面展现,其实是系统替咱们做了。

下面这个例子里面我只是定义了一个用来呈现列表项

内容的xml布局,并不包含ListActivity的界面布局。

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="horizontal" >
 6 
 7     <ImageView
 8         android:id="@+id/list_item_image"
 9         android:layout_width="wrap_content"
10         android:layout_height="wrap_content" />
11 
12     <LinearLayout
13         android:layout_width="wrap_content"
14         android:layout_height="wrap_content"
15         android:orientation="vertical" >
16         <TextView 
17             android:id="@+id/list_item_title"
18             android:layout_width="wrap_content"
19             android:layout_height="wrap_content"
20             />
21         <TextView 
22             android:id="@+id/list_item_info"
23             android:layout_width="wrap_content"
24             android:layout_height="wrap_content"
25             />
26     </LinearLayout>
27 
28 </LinearLayout>
list_item_layout.xml

相关文章:

  • 2021-11-28
  • 2021-05-26
  • 2021-10-29
  • 2021-10-05
  • 2021-05-13
  • 2021-08-13
  • 2022-02-07
猜你喜欢
  • 2021-08-30
  • 2022-01-29
  • 2021-08-26
  • 2021-12-25
  • 2021-07-31
相关资源
相似解决方案