listview使用方法
来源:互联网 发布:linux重启mysql数据库 编辑:程序博客网 时间:2024/05/01 08:50
转载:http://www.cnblogs.com/allin/archive/2010/05/11/1732200.html
listview使用方法:
列表的显示需要三个元素:
1.ListVeiw 用来展示列表的View。
2.适配器 用来把数据映射到ListView上的中介。
3.数据 具体的将被映射的字符串,图片,或者基本组件。
根据列表的适配器类型,列表分为三种,ArrayAdapter,SimpleAdapter和SimpleCursorAdapter
其中以ArrayAdapter最为简单,只能展示一行字。SimpleAdapter有最好的扩充性,可以自定义出各种效果。SimpleCursorAdapter可以认为是SimpleAdapter对数据库的简单结合,可以方面的把数据库的内容以列表的形式展示出来。
我们从最简单的ListView开始:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* @author allin
*
*/
public
class
MyListView
extends
Activity {
private
ListView listView;
//private List<String> data = new ArrayList<String>();
@Override
public
void
onCreate(Bundle savedInstanceState){
super
.onCreate(savedInstanceState);
listView =
new
ListView(
this
);
listView.setAdapter(
new
ArrayAdapter<String>(
this
, android.R.layout.simple_expandable_list_item_1,getData()));
setContentView(listView);
}
private
List<String> getData(){
List<String> data =
new
ArrayList<String>();
data.add(
"测试数据1"
);
data.add(
"测试数据2"
);
data.add(
"测试数据3"
);
data.add(
"测试数据4"
);
return
data;
}
}
0 0
- ListView使用方法
- listview使用方法
- listview 使用方法
- ListView的使用方法
- GridView、ListView、Repeater使用方法
- LISTVIEW的使用方法
- android ListView的使用方法
- ListView控件的使用方法
- ListView控件使用方法
- ListView的基本使用方法
- c# listview 使用方法
- Android ListView使用方法
- ListView的使用方法
- android Listview使用方法
- 【转载】ListView的使用方法
- ListView的使用方法
- ListView+BaseAdapter的使用方法
- ListView的使用方法总结
- Photos.frameWork
- 图像变换 - 图像拉伸、收缩、扭曲、旋转[1] - 仿射变换(cvWarpAffine)
- The auxService:mapreduce_shuffle does not exist 问题解决记录
- SAP模块常用增强总结
- linux下安装Django
- listview使用方法
- location方法详解,获取地址栏URL请求参数,以对象形式保存
- 流行的更换图片的javascript函数集--MM_swapImage函数和MM_swapImgRestore函数
- 漫谈android系统(2)androidLK启动过程1
- Android硬件访问服务框架分析
- 浅谈iOS中的蓝牙技术(一) --GameKit.framework
- 一般我们app涉及到的库
- char *p[5] 和 char p[5][10] 和 char **p的区别
- Elasticsearch基础教程