android学习笔记之ListView

本文介绍了如何使用Android中的ListActivity创建列表应用,并演示了如何通过SimpleAdapter填充ListView数据。此外,还提供了设置点击监听器的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ListView

继承ListActivity类

ListActivity的默认布局由一个位于屏幕中心的全屏列表构成。如果你不想使用默认的布局,可以在onCreate()方法中通过setContentView()方法设定你自己的布局。

如果指定你自己定制的布局,你的布局中必须包含一个id为"@id/android:list"的ListView。 若你还指定了一个id为"@id/android:empty"的view,当ListView中没有数据要显示时,这个view就会被显示,同时ListView会被隐藏。

ArrayList<HashMap<String,String>>list = new ArrayList< ArrayList<HashMap<String,String>>();

HashMap<String,String> map1 = newHashMap<String,String>();

HashMap<String,String> map2 = newHashMap<String,String>();

HashMap<String,String> map3 = newHashMap<String,String>();

map1.put(“user_name”, “zhangsan”);

map1.put(“user_ip”, “192.168.0.1”);

map2put(“user_name”, “lisi

map2put(“user_ip”, “192.168.0.2);

map3put(“user_name”, “wangwu

map3put(“user_ip”, “192.168.0.3);

list.add(map1);

list.add(map2;

list.add(map3)

SimpleAdapter listAdapter = newSimpleAdapter(this, R.layout.user, new String[]{“user_name”, “user_ip”}, newint[]{R.id.user_name, R.id.user_ip{};

setListAdapter(listAdapter);

点击响应函数:

protected void onListItemClick(ListView l,View v, int position, long id)

{

Super.onListItemClick(l,v, position, id);

System.out.println(“id:” + id);

System.out.println(“position:” + position);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值