Android中ListView的用法

2014-11-24 07:43:28 · 作者: · 浏览: 2

ListView是一个经常用到的控件,ListView里面的每个子项Item可以使一个字符串,也可以是一个组合控件。先说说ListView的实现:


1.准备ListView要显示的数据 ;


2.使用 一维或多维 动态数组 保存数据;


2.构建适配器 , 简单地来说, 适配器就是 Item数组 , 动态数组 有多少元素就生成多少个Item;


3.把 适配器 添加到ListView,并显示出来。



接下来,看看本文代码所实现的ListView:


接下来,就开始UI的XML代码:


main.xml代码如下,很简单,也不需要多做解释了:


< xmlversion="1.0"encoding="utf-8" >



android:id="@+id/LinearLayout01"


android:layout_width="fill_parent"


android:layout_height="fill_parent"


xmlns:android="http://schemas.android.com/apk/res/android">




android:layout_height="wrap_content"


android:id="@+id/MyListView">