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. 今天刚申请成为Uber司机 已经接了5单了....大家有什么想问的吗?

    今天刚申请成为Uber司机  已经接了5单了....大家有什么想问的吗? 滴滴快车单单2.5倍,注册地址:http://www.udache.com/如何注册Uber司机(全国版最新最详细注册流程)/ ...

  2. Color the ball(树状数组+线段树+二分)

    Color the ball Time Limit : 9000/3000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tota ...

  3. Linux vsftpd服务配置具体解释

    [背景] 近日.一朋友dominoserver要进行升级.迁移,搭建了linux測试系统,也开启vsftpd服务,但是配置的ftp账号,程序无法正常下载附件. [问题跟踪] 通过ftpclient连接 ...

  4. Learn Python The Hard Way, 2nd Edition 尾声

    看完了这本书,你决定继续做编程.也许它能成为你的一个职业,也许它能成为你的一项爱好.但你需要一些指导,确保自己不会走错了道路,或帮助你从这个新业余爱好中得到最大的乐趣. 我做了很久的编程.久的你都想象 ...

  5. sql server中的系统数据库

    1.master数据库 master是SQL Server中最重要的数据库,是整个数据库服务器的核心.用户不能直接修改该数据库,如果损坏了master数据库,整个SQL Server服务器将不能工作. ...

  6. 二十三种设计模式及其python实现

    本文源码寄方于github:https://github.com/w392807287/Design_pattern_of_python 参考文献: <大话设计模式>——吴强 <Py ...

  7. JavaSE学习总结第10天_面向对象5

      10.01 运动员和教练案例分析 教练和运动员案例:运动员分乒乓球运动员和篮球运动员,教练分乒乓球教练和篮球教练.为了出国交流,跟乒乓球相关的人员都需要学习英语. 分析: 10.02 运动员和教练 ...

  8. python--内建函数(1)

    Python中,按照对象是否可变,将类型分类为: 不可变类型:对象的内容不能够改变(not mutable),这些类型中主要有数值类型(整数,浮点数,复数),字符串类型,元组等 可变类型:对象的内容能 ...

  9. QMessageBox 用法

    案例一:QMessageBox msgBox;msgBox.setText("The document has been modified.");msgBox.setInforma ...

  10. 谷歌三大核心技术(三)Google BigTable中文版

    谷歌三大核心技术(三)Google BigTable中文版 Bigtable:一个分布式的结构化数据存储系统 译者:alex 摘要 Bigtable是一个分布式的结构化数据存储系统,它被设计用来处理海 ...