simpleAdapter讲解
来源:互联网 发布:mac系统镜像ios下载 编辑:程序博客网 时间:2024/06/05 04:42
1、创建一个simple_item.xml文件,用来存放数据源
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="数据"/>
<TextView
android:id="@+id/intro"
android:textSize="20sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="介绍"/>
</LinearLayout>
2、在activity_main.xml中新建一个listview适配器view
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
3、初始化listview并找到对应id
private ListView lv;
lv=(ListView) findViewById(R.id.lv);
4、新建一个list数据源,并初始化
private List<Map<String, Object>> list;
list=new ArrayList<Map<String,Object>>();
Map<String, Object>
List集合中的对象是一个Map对象,而这个Map对象的键是String类型,值是Object类型
5、新建一个map对象并初始化map
private Map<String, Object> map;
//用一个for循环来添加map每个key只能映射一个value
for (int i = 0; i < 40; i++) {map=new HashMap<String, Object>();map.put("name", "数据"+i);map.put("intro", "介绍"+i);list.add(map);}
6、新建一个adapter对象,并将适配器添加到listview中
simpleadapter中的五个参数:
第一个参数 表示访问整个android应用程序接口,基本上所有的组件都需要
第二个参数表示生成一个Map(String ,Object)列表选项
第三个参数表示界面布局的id 表示该文件作为列表项的组件
第四个参数表示该Map对象的哪些key对应value来生成列表项
第五个参数表示来填充的组件 Map对象key对应的资源一依次填充组件 顺序有对应关系
adapter=new SimpleAdapter(this, list, R.layout.simple_item, from, to);lv.setAdapter(adapter);
5、
5
- simpleAdapter讲解
- Adapter基础讲解-SimpleAdapter使用示例:
- SimpleAdapter
- simpleAdapter
- SimpleAdapter
- SimpleAdapter
- SimpleAdapter
- simpleAdapter
- SimpleAdapter
- SimpleAdapter
- SimpleAdapter
- SimpleAdapter
- simpleAdapter
- SimpleAdapter
- SimpleAdapter
- SimpleAdapter
- SimpleAdapter
- SimpleAdapter
- 贪心算法--Dijkstra算法(单源最短路径算法)
- C
- java condition 使用及分析
- 国内Ubuntu下载地址
- 查询和索引的优化
- simpleAdapter讲解
- Linux 系统压缩和解压命令总结
- 校招提前批之今日头条一面
- HDU 2732 Leapin' Lizards(拆点+最大流)
- OpenGL与CUDA互操作方式总结
- 为什么普通树没有中序遍历和森林没有后序遍历的自己见解
- Thinkphp 模型->动态查询
- Java中的枚举类型enum的使用
- Activity和Fragment生命周期