package com.funfree.view;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;
/**
* 功能:演示最简单的ListView控件的使用方式
* 作者:Arkliszeng
* 时间:2011-06-08
* 地点:北大青鸟锦江中心学术部
* 版本:ver 1.0.0
*
* @author AZ
*
*/
public class ListViewActivity extends ListActivity {
/** Called when the activity is first created. */
private SimpleAdapter listAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList<Map<String, String>> list = new ArrayList<Map<String,
String>>();
//初始化集合
init(list);
// 生成一个SimpleAdapter类型的变量来填充数据--这里关键代码
listAdapter = new SimpleAdapter(this, list,
R.layout.user, new String[] { "user_name", "user_pasword" },
new int[] { R.id.user_name, R.id.user_pasword });
// 设置显示ListView
setListAdapter(listAdapter);
}
private void init(ArrayList<Map<String, String>> list) {
// TODO Auto-generated method stub
// 使用Map来表示列表数据
Map<String, String> mapOne = new HashMap<String, String>();
Map<String, String> mapTwo = new HashMap<String, String>();
Map<String, String> mapThree = new HashMap<String, String>();
Map<String, String> mapFour = new HashMap<String, String>();
Map<String, String> mapFive = new HashMap<String, String>();
Map<String, String> mapSix = new HashMap<String, String>();
mapOne.put("user_name", "徐嵩");
mapOne.put("user_pasword", "要你命三千");
mapTwo.put("user_name", "陈竞强");
mapTwo.put("user_pasword", "不死的小强");
mapThree.put("user_name", "彭阳剑");
mapThree.put("user_pasword", "Only you到你死");
mapFour.put("user_name", "张宁");
mapFour.put("user_pasword", "QQ无罪");
mapFive.put("user_name", "庄鹏飞");
mapFive.put("user_pasword", "C++之神");
mapSix.put("user_name", "曾忠");
mapSix.put("user_pasword", "打酱油的站神");
list.add(mapOne);
list.add(mapTwo);
list.add(mapThree);
list.add(mapFour);
list.add(mapFive);
list.add(mapSix);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
System.out.println("id = " + id);
// 显示所单击条目的位置数
System.out.println("第 " + position + " 项");
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
演示Android的ListView控件的使用
共24个文件
class:7个
xml:5个
png:3个
4星 · 超过85%的资源 需积分: 9 260 下载量 196 浏览量
2011-06-09
09:53:16
上传
评论 3
收藏 44KB RAR 举报
温馨提示
环境:Windows XP SP3、JDK 1.6、Android SDK 3.0、 Eclipse galileo 3.4、AVD 2.2 使用步骤: 1、下载解压之后,使用IDE导入工程 2、运行工程 3、如果一切正常,那么你会在虚拟设备中看到ListView列表内容 目的:熟悉ListView控件的用法--使用ListView必须让Activity继承ListActivity类,并且在main.xml布局描述文档中,ListView类的android.id必须是"@+id/android:list”值。
资源推荐
资源详情
资源评论
收起资源包目录
DemoListView.rar (24个子文件)
DemoListView
.project 848B
default.properties 362B
bin
com
funfree
view
R$string.class 478B
R$layout.class 416B
ListViewActivity.class 3KB
R$drawable.class 394B
R.class 517B
R$attr.class 334B
R$id.class 445B
DemoListView.apk 15KB
resources.ap_ 11KB
classes.dex 4KB
proguard.cfg 1KB
AndroidManifest.xml 774B
src
com
funfree
view
ListViewActivity.java 2KB
AndroidManifest.out.xml 0B
res
values
strings.xml 268B
layout
main.xml 652B
user.xml 1013B
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 4KB
drawable-mdpi
icon.png 3KB
.classpath 280B
gen
com
funfree
view
R.java 995B
assets
共 24 条
- 1
技术大黍-曾老师
- 粉丝: 109
- 资源: 108
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页