1、视图

1)主视图

 <RelativeLayout 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"
tools:context=".MainActivity" > <ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lv"
></ListView> </RelativeLayout>

2)item视图

 <?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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/iv"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv"
/> </LinearLayout>

2、java代码

 package com.example.simpleadapter;

 import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ListView;
import android.widget.SimpleAdapter; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); ListView lv = (ListView)findViewById(R.id.lv); List<Map<String,Object>> data = new ArrayList<Map<String,Object>>();
Map<String,Object> map1 = new HashMap<String,Object>();
map1.put("nametext", "我是第一个功能");
map1.put("iconid", R.drawable.btn_minus_disable_focused); Map<String,Object> map2 = new HashMap<String,Object>();
map2.put("nametext", "我是第二个功能");
map2.put("iconid", R.drawable.btn_minus_selected); Map<String,Object> map3 = new HashMap<String,Object>();
map3.put("nametext", "我是第三个功能");
map3.put("iconid", R.drawable.btn_radio_off_selected); Map<String,Object> map4 = new HashMap<String,Object>();
map4.put("nametext", "我是第四个功能");
map4.put("iconid", R.drawable.btn_radio_on_focused_holo_dark); Map<String,Object> map5 = new HashMap<String,Object>();
map5.put("nametext", "我是第五个功能");
map5.put("iconid", R.drawable.btn_radio_on_holo_dark); data.add(map1);
data.add(map2);
data.add(map3);
data.add(map4);
data.add(map5); lv.setAdapter(new SimpleAdapter(this, data, R.layout.list_item, new String[]{"nametext","iconid"}, new int[]{R.id.tv,R.id.iv}));
} }

SimpleAdapter的更多相关文章

  1. Android应用项目中BaseAdapter、SimpleAdapter和ArrayAdapter中的三种适配器

    一.写在前面: 本次我们来讲解一下Android应用中三个适配器:BaseAdapter.SimpleAdapter和ArrayAdapter.其中常见的是BaseAdapter,也是个人推荐使用的适 ...

  2. Android日记-SimpleAdapter和BaseAdapter

    SimpleAdapter 这是一个简单的适配器,可以将静态数据映射到XML文件中定义好的视图.你可以指定由Map组成的List(比如ArrayList)类型的数据.在ArrayList中的每个条目对 ...

  3. 关于SimpleAdapter和ListView结合使用,实现列表视图的笔记

    使用ListView需要为其添加适配器: 适配器有两种:1.ArrayAdapter  --用于单独文字显示 2.SimpleAdapter --用于文字和图片显示 这里主要记录SimpleAdapt ...

  4. XML文件解析并利用SimpleAdapter将解析结果显示在Activity中

    首先创建一个实体类 Mp3Info用来存储解析的XML文件中的内容: public class Mp3Info implements Serializable{ private static fina ...

  5. Android UI:ListView -- SimpleAdapter

    SimpleAdapter是扩展性最好的适配器,可以定义各种你想要的布局,而且使用很方便. layout : <?xml version="1.0" encoding=&qu ...

  6. 深入理解使用ListView时ArrayAdapter、SimpleAdapter、BaseAdapter的原理

    在使用ListView的时候,我们传给setAdapter方法的Adapter通常是ArrayAdapter.SimpleAdapter.BaseAdapter,但是这几个Adapter内部究竟是什么 ...

  7. SimpleAdapter的使用

    SimpleAdapter的使用       SimpleAdapter是一个简单的适配器,该适配器也继承了BaseAdapter,对于布局是固定而言,使用简单适配器开发时非常简单了,由于Simple ...

  8. 转载《SimpleAdapter的参数说明》

    SimpleAdapter的参数说明 第一个参数 表示访问整个android应用程序接口,基本上所有的组件都需要 第二个参数表示生成一个Map(String ,Object)列表选项 第三个参数表示界 ...

  9. Android学习---ListView的点击事件,simpleAdapter和arrayadapter,SimpleCursoAdapter的原理和使用

    如题,本文将介绍 listview的点击事件,simpleAdapter和arrayadapter的原理和使用. 1.ListView的注册点击事件 //注册点击事件 personListView.s ...

  10. Android开发学习之路-SimpleAdapter源码分析学习

    今天在课堂上,老师用到了SimpleAdapter,然后女神在边上问我为什么这个SimpleAdapter不能做到我app那种带有进度条的效果,言语说不清,然后就开始看源代码,发现这个Adapter的 ...

随机推荐

  1. Bitmap recycle()

    Bitmap调用recycle? When? Bitmap有一个recycle方法,意思非常easy,回收Bitmap的空间. Q 1: Bitmap是否有调用recycle方法的必要性? A: 嵌入 ...

  2. JNI(2)

    JNI(2) 访问字段和方法 JNI允许本地代码访问java 对象的字段和方法. 调用需要两个步骤: 例如调用cls类的f方法, 1. 获取方法ID jmethodID mid = env->G ...

  3. IE升级到10.0,VS2010启动调试时报“未能将脚本调试器附加到计算机..”

    IE升级到10.0,VS2010启动调试时报“未能将脚本调试器附加到计算机..” 今天,在调试代码时,调试器弹出提示框,报:未能将脚本调试器附加到计算机XXX上的进程iexplore.exe . 已附 ...

  4. CSS一些设置用法

    今天就简单写点的知识点 1. CSS字体样式小结 1) text-indent :值  实现段落首行缩进功能   (在起初我们编写段落时为了实现首行缩进两个字符时用的是HTML的标签元素&nb ...

  5. 根据选择项过滤GridView

    前台代码: <div> <asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPos ...

  6. 使用PowerShell 命令集进行SQL Server 2012 备份和还原

    最近心相不错,所以打算翻译一些英文文档做福利,原文在此,翻译有不足的地方还请各位兄弟指点. 讨论什么是DBA最重要的工作的时候,你最常听到就是一条就是DBA只要做好备份和恢复.事实如此,如果你不做备份 ...

  7. HDU1004题解分析(字符串处理)

    这道题是从上个星期开始做的,看到题时觉得似曾相似,好像做过,理了一下思路敲完代码又不对,后来发现是数组用错了,之后又重新想了数组和比较用法,昨天改了一个多小时,后来样例输出全部正确,所有情况都考虑到了 ...

  8. php随笔9-thinkphp OA系统 集成UEditor

    版本信息:thinkphp 3.1.3 full     UEditor 1.4.3.1 utf8-php 1.将EUditor放在项目public目录下. 2.在指定页面加载编辑器 <!-- ...

  9. php随笔5-thinkphp OA系统 人力资源管理

    最近闲来无事,自己尝试通过thinkphp3.1.3框架开发一套自己的OA系统,目前已完成了人力资源管理部分的内容,遇到并解决了几个问题. 1.由于刚开始不太熟悉thinkphp的框架,花费了一些功夫 ...

  10. HttpClient发送get post请求和数据解析

    最近在跟app对接的时候有个业务是微信登录,在这里记录的不是如何一步步操作第三方的,因为是跟app对接,所以一部分代码不是由我写,我只负责处理数据,但是整个微信第三方的流程大致都差不多,app端说要传 ...