Android SimpleAdapter的参数
1.作用是ArrayList和 ListView的桥梁。这个ArrayList里边的每一项都是一个Map<String,?>类型。
ArrayList当中的每一项 Map对象都和ListView里边的每一项进行数据绑定一一对应。
2.SimpleAdapter的构造函数:
SimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to)
参数:
1.context:上下文。
2.data:基于Map的list。Data里边的每一项都和 ListView里边的每一项对应。Data里边的每一项都是一个Map类型,这个Map类里边包含了ListView每一行需要的数据。
3.resource :就是一个布局layout,可引用系统提供的,也可以自定义。
4.from:这是个名字数组,每个名字是为了在 ArrayList数组的每一个item索引Map<String,Object>的Object用的。即 map 中得key值
5.to:里面是一个TextView数组。这些 TextView是以id的形式来表示的。例如:Android.R.id.text1,这个text1在layout当中是可以索引的。
3.通过一个类子来理解下:
listitem.xml文件:
<?xml version=”1.0″ encoding=”utf-″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”horizontal” android:layout_width=”fill_parent”
android:layout_height=”wrap_content”>
<TextView android:id=”@+id/TextView01″ android:layout_width=”100px”
android:layout_height=”wrap_content” />
<TextView android:id=”@+id/TextView02″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content” />
</LinearLayout>
下面是activity文件的部分代码
List<Map<String, Object>> data = new ArrayList<Map<String,Object>>();
Map<String,Object> item;
item = new HashMap<String,Object>();
item.put(“姓名”,”张三”);
item.put(“性别”,”男”);
data.add(item);
item = new HashMap<String,Object>();
item.put(“姓名”,”李四”);
item.put(“性别”,”女”);
data.add(item);
// 上面是构造数据部分。
ListView listview= new ListView(this);
//构造listview对象。
SimpleAdapter adapter = new SimpleAdapter(this,data,R.layout.listitem,new String[]{“姓名”,”性别”},new int[]{R.id.TextView01,R.id.TextView02});
/*构造一个适配器。
* 1,第三个参数是说明用的是自定义的布局R.layout.listtiem。
* 2,第四和第五个参数一起理解:
* 把我们添加数据时姓名那一列对应到R.id.TextView01这个TextView中,把性别对应到R.id.TextView02这个 TextView中。
* 如果把from改为new String[]{“姓名”,”姓名”},测试下就会明白。
*/
listview.setAdapter(adapter);
setContentView(listview);
Android SimpleAdapter的参数的更多相关文章
- android fragment传递参数_fragment之间传值的两种方法
在Activity中加载Fragment的时候.有时候要使用多个Fragment切换.并传值到另外一个Fragment.也就是说两个Fragment之间进行参数的传递.查了很多资料.找到两种方法.一种 ...
- Android Stuido 方法参数 p0,p1
Android Stuido 方法参数 p0,p1 参考文献 https://stackoverflow.com/questions/49219439/incorrect-variable-names ...
- Android SimpleAdapter源码详解
一直没认真看过android的源码,也不太敢看,稀里糊涂也敲了一年的代码,现在想好好学习了,就把常用的源码都看了一下,小伙伴们来涨姿势吧,有错误的地方,直接指出,我脸厚不怕丢人.来吧. 刚开始学and ...
- Android SimpleAdapter ListView (锁定手机,解锁手机的列表)
SimpleAdapter是扩展性最好的适配器,可以定义各种你想要的布局. 构造方法: SimpleAdapter(Context context, List<? extends Map< ...
- Android HttpURLConnection Post 参数 (https)
声明utf-8: public static String CHARSET_UTF8 = HTTP.UTF_8; eg:登陆请求方法,通过接口返回结果: public static void logi ...
- Android 系统默认参数的修改
转自: http://www.th7.cn/Program/Android/201505/447097.shtml 写在前面的话 一般在新项目开始之初,我们需要针对客户需求进行各种系统默认属性的配置, ...
- Android Handler传递参数动态更新UI界面demo
package com.example.demo_test; import android.app.Activity; import android.os.Bundle; import android ...
- Android SimpleAdapter GridView (网格图片点击放大显示)
GridView网格视图 GridView网格视图是按照行,列分布的方式来显示多个组件,通常用于显示图片或是图标等,在使用网格视图时,首先需要要在屏幕上添加GridView组件. 常用属性: 1. a ...
- Android jni 编程(参数的传递,成员,方法的)相互访问
package com.test.androidjni; import android.app.Activity; import android.os.Bundle; import android.u ...
随机推荐
- MySQL密码修改(四)
一.修改破解MySQL密码 1.1:修改密码 在知道原始密码的情况下 [root@web1 ~]# mysqladmin -uroot -p -S /home/mysql/3307/mysql.soc ...
- POJ 1036
#include<iostream> #include<algorithm> #define MAXN 205 using namespace std; struct node ...
- 远程连接MySQL提示 Host is not allowed to connect to this MySQL server
进入连接的主机修改系统数据库MySQL 下面的user表,把User= root(这里可能是其他你所需要连接的用户名)的这行数据的Host从localhost改为% 如下图: 修改完之后一定要重启My ...
- Mac下使用zsh不执行/etc/profile文件
Mac下使用了zsh会不执行/etc/profile文件,当然,如果用原始的是会执行. 转而执行的是这两个文件,每次登陆都会执行: ~/.zshrc与/etc/zshenv与/etc/zshrc 所以 ...
- sublime text ubuntu
{ "color_scheme": "Packages/User/SublimeLinter/Dawn (SL).tmTheme", "font_fa ...
- CS231n学习笔记-图像分类笔记(下篇)
原文地址:智能单元 K-Nearest Neighbor分类器 大家可能注意到了,为什么只用最相似的一张图片的标签来作为测试图像的标签呢?这不是很奇怪吗!是的,使用K-Nearest Neighbor ...
- Elasticsearch Aggregation 多个字段分组统计 Java API实现
现有索引数据: index:school type:student --------------------------------------------------- {"grade&q ...
- 分布式ID生成方法-趋势有序的全局唯一ID
一.需求缘起 几乎所有的业务系统,都有生成一个记录标识的需求,例如: (1)消息标识:message-id (2)订单标识:order-id (3)帖子标识:tiezi-id 这个记录标识往往就是数据 ...
- zookeeper集群搭建及Leader选举算法源码解析
第一章.zookeeper概述 一.zookeeper 简介 zookeeper 是一个开源的分布式应用程序协调服务器,是 Hadoop 的重要组件. zooKeeper 是一个分布式的,开放源码的分 ...
- Zookeeper初见
这是Zookeeper学习总结 的系列文章. ZK简介 ZK部署及运行 ZK的常用API 创建会话 创建节点 删除节点 读取数据节点 更新数据 检测节点是否存在 ZK的开源封装