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. AlertDialog弹出时背景明暗程度调整

    今天有个需求是把弹出AlertDialog时的变暗的背景调整得不要那么暗. 一开始懒惰就直接百度中文搜索,结果找到的代码试了几次都不行. 后来老老实实开google.stackoverflow搜索,搜 ...

  2. 学习日记之模板方法模式和 Effective C++

    模板方法模式: 定义:定义一个操作中的算法的骨架.而将一些步骤延伸到子类中.模板方法使得子类能够不改变算法的结构就可以重定义该算法的某些特定步骤. (1),用了继承,而且肯定这个继承有意义的情况下.就 ...

  3. C#静态方法

    C#静态方法     学习C#静态函数及变量的一个精典例子与代码 (1)用于对静态字段.只读字段等的初始化. (2)添加static关键字,不能添加访问修饰符,因为静态构造函数都是私有的. (3)类的 ...

  4. json与字符串互转

    1 字符串转JSON var obj=eval('('+str+")') var obj=JSON.parse(str) var obj=str.parseJSON() 2 JSON转字符串 ...

  5. js 乱码解决方案

    如果网页编码规则是utf-8,即在网页头部中可以看到如下代码: 那么js文件中如果有中文字,调用输出时就会出现乱码.解决此个问题的办法如下: 即在引用javascript输出的地方加上charset= ...

  6. Android之判断设备网络连接状态,并判断连接方式

    在Android开发过程中,对于一个需要连接网络的Android设备,对设备的网络状态检测是很有必要的!有很多的App都需要连接网络.判断设备是否已经连接网络,并且在连接网络的状态下判断是wifi无线 ...

  7. Apache+php+mysql+phpadmin搭建

    一,准备工具. httpd-2.4.12-win32-VC9.zip php-5.4.40-Win32-VC9-x86.zip phpMyAdmin-4.2.13.2-all-languages my ...

  8. eclipse没有New Java Class的解决办法

    配置之前的截图: 配置步骤:

  9. python2.7_1.3_获取远程设备的IP地址

    代码如下: # -*- coding: utf-8 -*- import socket def get_remote_machine_info(): remote_host = 'www.python ...

  10. stackoverflow,stackexchange,zhihu,ilewen,segmentfault,answerhub,question2answer,,

    http://stackexchange.com/ http://question2answer.org/ http://answerhub.com/qa/ http://segmentfault.c ...