android-listview控件
第一:修改xml文件
<ListView
android:id="@id/android:list" //必须这么写,不然后报错
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
第二:设置适配器
extends ListActivity //修改继承的父类
SimpleAdapter listadapter = new SimpleAdapter(this, getdate(), R.layout.vlist, new String[]{"title","info"}, new int[]{R.id.textview1,R.id.textview2});
setListAdapter(listadapter);
第三:添加数据
private List<HashMap<String,Object>> getdate() {
// TODO Auto-generated method stub
ArrayList<HashMap<String,Object>> list= new ArrayList<HashMap<String,Object>>();
HashMap<String,Object> map1 = new HashMap<String,Object>();
HashMap<String,Object> map2 = new HashMap<String,Object>();
map1.put("title", "aaaa");
map1.put("info", "bbb");
map2.put("title", "cccc");
map2.put("info", "dddd");
list.add(map1);
list.add(map2);
return list;
}
第四:设置监听器
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
if(0==id){
System.out.println("0");
}
else if(1==id)
{
System.out.println("1");
}
}
更多相关文章
- Android中ListView以及数组适配器(ArrayAdapter)的使用
- Android 网格视图(GirdView)简易适配器的使用
- Android回顾--(九) ListView和自定义适配器
- Android中的适配器(Adapter)
- 一起看看PHP设计模式之适配器模式
- 什么是适配器模式,它有哪些应用场景
- php策略模式和适配器模式的区别
- 适配器模式在开源代码中的应用
- 过滤器监听器面试题都在这里