转载《SimpleAdapter的参数说明》
SimpleAdapter的参数说明
第一个参数 表示访问整个android应用程序接口,基本上所有的组件都需要
第二个参数表示生成一个Map(String ,Object)列表选项
第三个参数表示界面布局的id 表示该文件作为列表项的组件
第四个参数表示该Map对象的哪些key对应value来生成列表项
第五个参数表示来填充的组件 Map对象key对应的资源一依次填充组件 顺序有对应关系
注意的是map对象可以key可以找不到 但组件的必须要有资源填充 因为 找不到key也会返回null 其实就相当于给了一个null资源
下面的程序中如果 new String[] { "name", "head", "desc","name" } new int[] {R.id.name,R.id.head,R.id.desc,R.id.head}
这个head的组件会被name资源覆盖
这个key就是第四个参数,而第四个参数表示去list里面拿数据,第五个参数表示拿到的数据显示在那个组件中;第三个参数只是一个布局的xml文件;xml文件中有多个组件,这些组件显示什么数据 就是后面两个参数的作用
代码
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal"
- tools:context=".MainActivity" >
- <ListView
- android:id="@+id/lt1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" >
- </ListView>
- </LinearLayout>
- <?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="horizontal" >
- <ImageView
- android:id="@+id/head"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:paddingLeft="10dp" />
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical" >
- <TextView
- android:id="@+id/name"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="20dp"
- android:textColor="#f0f"
- android:paddingLeft="10dp"/>
- <TextView
- android:id="@+id/desc"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="14dp"
- android:paddingLeft="10dp"/>
- </LinearLayout>
- </LinearLayout>
- package com.example.simpleadptertest;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.Menu;
- import android.widget.ListView;
- import android.widget.SimpleAdapter;
- public class MainActivity extends Activity {
- private String[] name = { "剑萧舞蝶", "张三", "hello", "诗情画意" };
- private String[] desc = { "魔域玩家", "百家执行", "高级的富一代", "妹子请过来..一个善于跑妹子的。。" };
- private int[] imageids = { R.drawable.libai, R.drawable.nongyu,
- R.drawable.qingzhao, R.drawable.tiger };
- private ListView lt1;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- List<Map<String, Object>> listems = new ArrayList<Map<String, Object>>();
- for (int i = 0; i < name.length; i++) {
- Map<String, Object> listem = new HashMap<String, Object>();
- listem.put("head", imageids[i]);
- listem.put("name", name[i]);
- listem.put("desc", desc[i]);
- listems.add(listem);
- }
- /*SimpleAdapter的参数说明
- * 第一个参数 表示访问整个android应用程序接口,基本上所有的组件都需要
- * 第二个参数表示生成一个Map(String ,Object)列表选项
- * 第三个参数表示界面布局的id 表示该文件作为列表项的组件
- * 第四个参数表示该Map对象的哪些key对应value来生成列表项
- * 第五个参数表示来填充的组件 Map对象key对应的资源一依次填充组件 顺序有对应关系
- * 注意的是map对象可以key可以找不到 但组件的必须要有资源填充 因为 找不到key也会返回null 其实就相当于给了一个null资源
- * 下面的程序中如果 new String[] { "name", "head", "desc","name" } new int[] {R.id.name,R.id.head,R.id.desc,R.id.head}
- * 这个head的组件会被name资源覆盖
- * */
- SimpleAdapter simplead = new SimpleAdapter(this, listems,
- R.layout.simple_item, new String[] { "name", "head", "desc" },
- new int[] {R.id.name,R.id.head,R.id.desc});
- lt1=(ListView)findViewById(R.id.lt1);
- lt1.setAdapter(simplead);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- }
转载《SimpleAdapter的参数说明》的更多相关文章
- 转载《Android LayoutInflater详解》
在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于findViewById().不同点是LayoutInflater是用来找res/layout/下的xml布局文件,并且实例 ...
- Android LayoutInflater详解
在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于findViewById().不同点是LayoutInflater是用来找res/layout/下的xml布局文件,并且 ...
- Android LayoutInflater详解(转)
在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于findViewById().不同点是LayoutInflater是用来找res/layout/下的xml布局文件,并且实例 ...
- Android LayoutInflater详解 (转)
在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于findViewById().不同点是LayoutInflater是用来找res/layout/下的xml布局文件,并且实例 ...
- Android——LayoutInflater详解
在实际工作中,事先写好的布局文件往往不能满足我们的需求,有时会根据情况在代码中自定义控件,这就需要用到LayoutInflater. LayoutInflater在Android中是"扩展& ...
- <转> Android LayoutInflater详解
在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于findViewById().不同点是LayoutInflater是用来找res/layout/下的xml布局文件,并且实例 ...
- [ 转载 ] Android设计模式详解
从Android再来认识23种设计模式 ReadyShow 关注 0.2 2018.01.06 23:18* 字数 3855 阅读 2584评论 0喜欢 20 概况来看本文章的内容 创建型:5个 单 ...
- Android Notification 详解(一)——基本操作
Android Notification 详解(一)--基本操作 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Notification 文中如有纰 ...
- Android Notification 详解——基本操作
Android Notification 详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 前几天项目中有用到 Android 通知相关的内容,索性把 Android Notificatio ...
- Android ActionBar详解
Android ActionBar详解 分类: Android2014-04-30 15:23 1094人阅读 评论(0) 收藏 举报 androidActionBar 目录(?)[+] 第4 ...
随机推荐
- Log4J详解
Log4J 简介 Log4j有三个主要的组件:Loggers(记录器),Appenders (输出源)和Layouts(布局).这里可简单理解为日志类别,日志要输出的地方和日志以何种形式输出.综合使 ...
- React Native 一个组件styles BUG
'use strict'; var React = require('react-native'); var { StyleSheet, PanResponder, View, Text } = Re ...
- GridView获取列子段的几种途径
GridView是ASP.NET中功能强大的数据显示控件,它的RowDataBound事件为我们提供了方便的控制行.列数据的途径. 要获取当前行的某个数据列,我在实践中总结有如下几种方法: 1. Ce ...
- Ubuntu Install Java
http://linuxpilot.com/ubuntu-java class HelloWorld{public static void main(String[]arg){System.out.p ...
- JAVA中SERIALVERSIONUID的解释
serialVersionUID作用: 序列化时为了保持版本的兼容性,即在版本升级时反序列化仍保持对象的唯一性.有两种生成方式: 一个是默认的1L,比如:private st ...
- RHEL6 --部署phpMyAdmin与论坛系统
一.rpm安装LAMP平台部署phpMyAdmin 二.搭建wordpress个人博客系统 三.搭建论坛系统 一.rpm安装LAMP平台及部署phpMyAdmin 1.phpMyAdmin简介及获取方 ...
- testlink安装
今天安装了一下testlink,完全按照高峻博客里的做法,最后安装成功了 遇到的问题: 问题表现: 新安装TestLink,登录Testlink后,新建一个项目后,会出现如下提示: There are ...
- GridView不能添加头布局,并且scrollView与GridView冲突导致一些页面无法融合
此贴为标记贴 方便下次使用 在项目需求中原本是用ScrollView来进行整个页面的滑动,ScrollView里面包含的有图片轮播,文字轮播,与2列GridView的item 问题 使用原生的Grid ...
- BootStrap框架
简介: Bootstrap,来自 Twitter,是目前很受欢迎的前端框架.Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加快捷,是一个CSS ...
- vim ---- 一键自动indent的命令
当用vim拷贝某一段代码到另一个程序的时候,往往indent会有一些问题.. 下面这个强大的命令能够让你一键让代码有很好的格式. gg=G 例子: