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的参数的更多相关文章

  1. android fragment传递参数_fragment之间传值的两种方法

    在Activity中加载Fragment的时候.有时候要使用多个Fragment切换.并传值到另外一个Fragment.也就是说两个Fragment之间进行参数的传递.查了很多资料.找到两种方法.一种 ...

  2. Android Stuido 方法参数 p0,p1

    Android Stuido 方法参数 p0,p1 参考文献 https://stackoverflow.com/questions/49219439/incorrect-variable-names ...

  3. Android SimpleAdapter源码详解

    一直没认真看过android的源码,也不太敢看,稀里糊涂也敲了一年的代码,现在想好好学习了,就把常用的源码都看了一下,小伙伴们来涨姿势吧,有错误的地方,直接指出,我脸厚不怕丢人.来吧. 刚开始学and ...

  4. Android SimpleAdapter ListView (锁定手机,解锁手机的列表)

    SimpleAdapter是扩展性最好的适配器,可以定义各种你想要的布局. 构造方法: SimpleAdapter(Context context, List<? extends Map< ...

  5. Android HttpURLConnection Post 参数 (https)

    声明utf-8: public static String CHARSET_UTF8 = HTTP.UTF_8; eg:登陆请求方法,通过接口返回结果: public static void logi ...

  6. Android 系统默认参数的修改

    转自: http://www.th7.cn/Program/Android/201505/447097.shtml 写在前面的话 一般在新项目开始之初,我们需要针对客户需求进行各种系统默认属性的配置, ...

  7. Android Handler传递参数动态更新UI界面demo

    package com.example.demo_test; import android.app.Activity; import android.os.Bundle; import android ...

  8. Android SimpleAdapter GridView (网格图片点击放大显示)

    GridView网格视图 GridView网格视图是按照行,列分布的方式来显示多个组件,通常用于显示图片或是图标等,在使用网格视图时,首先需要要在屏幕上添加GridView组件. 常用属性: 1. a ...

  9. Android jni 编程(参数的传递,成员,方法的)相互访问

    package com.test.androidjni; import android.app.Activity; import android.os.Bundle; import android.u ...

随机推荐

  1. 8.在XamarinAndroid上进一步控制包的大小

    在Android上链接 Xamarin.Android应用程序使用链接器来减小应用程序的大小.链接器使用应用程序的静态分析来确定哪些程序集.类型.成员被实际使用.链接器的行为就像一个GC,不断寻找被引 ...

  2. 腾讯云域名申请+ssl证书申请+springboot配置https

    阿里云域名申请 域名申请比较简单,使用微信注册阿里云账号并登陆,点击产品,选择域名注册 输入你想注册的域名 进入域名购买页面,搜索可用的后缀及价格,越热门的后缀(.com,.cn)越贵一般,并且很可能 ...

  3. 再学Java 之 解决No enclosing instance of type * is accessible

    深夜,临睡前写了个小程序,出了点小问题 public class Test_drive { public static void main(String[] args){ A a = new A(); ...

  4. Css权重解析

    Css权重解析 关于CSS权重,我们需要一套计算公式来去计算,这个就是 CSS Specificity,我们称为CSS 特性或称非凡性,它是一个衡量CSS值优先级的一个标准 具体规范入如下: spec ...

  5. Apache版本hadoop-2.6.0.tar.gz平台下搭建Hue

    不多说,直接上干货! http://archive.apache.org/dist/ http://www.cnblogs.com/smartloli/p/4527168.html http://ww ...

  6. 【原】Ubuntu ATI/Intel双显卡 驱动安装

    本文只针对含有AMD双显卡的部分机型,已经测试过的包括DELL Vostro 3550/DELL Inspiron 14R (AMD 6630 和 Intel HD 3000).整个安装过程需要使用命 ...

  7. java学习-get和post请求

    摘要 看完本文可以知道,使用java原生编写get/post请求的步骤,进行网络请求时应该注意的地方. 这里使用java自带的HttpUrlConnection对象进行网络请求, 请求步骤大致分为五步 ...

  8. Python的Django框架中forms表单类的使用方法详解

    用户表单是Web端的一项基本功能,大而全的Django框架中自然带有现成的基础form对象,本文就Python的Django框架中forms表单类的使用方法详解. Form表单的功能 自动生成HTML ...

  9. nginx的gzip模块

    gzip模块是我们在nginx里面经常用到的,压缩响应的数据,这通常有助于将传输数据的大小减少一半甚至更多.可以让我们访问网站更为流畅. Syntax Default Context gzip on ...

  10. Struts2配置文件struts.xml的编辑自动提示代码功能

    第一步:复制struts.xml头部地址 第二步:Window --->Preferences 第三步:XML--->XML Catalog--->Add 第四步:在Key中粘贴复制 ...