SimpleAdapter
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的更多相关文章
- Android应用项目中BaseAdapter、SimpleAdapter和ArrayAdapter中的三种适配器
一.写在前面: 本次我们来讲解一下Android应用中三个适配器:BaseAdapter.SimpleAdapter和ArrayAdapter.其中常见的是BaseAdapter,也是个人推荐使用的适 ...
- Android日记-SimpleAdapter和BaseAdapter
SimpleAdapter 这是一个简单的适配器,可以将静态数据映射到XML文件中定义好的视图.你可以指定由Map组成的List(比如ArrayList)类型的数据.在ArrayList中的每个条目对 ...
- 关于SimpleAdapter和ListView结合使用,实现列表视图的笔记
使用ListView需要为其添加适配器: 适配器有两种:1.ArrayAdapter --用于单独文字显示 2.SimpleAdapter --用于文字和图片显示 这里主要记录SimpleAdapt ...
- XML文件解析并利用SimpleAdapter将解析结果显示在Activity中
首先创建一个实体类 Mp3Info用来存储解析的XML文件中的内容: public class Mp3Info implements Serializable{ private static fina ...
- Android UI:ListView -- SimpleAdapter
SimpleAdapter是扩展性最好的适配器,可以定义各种你想要的布局,而且使用很方便. layout : <?xml version="1.0" encoding=&qu ...
- 深入理解使用ListView时ArrayAdapter、SimpleAdapter、BaseAdapter的原理
在使用ListView的时候,我们传给setAdapter方法的Adapter通常是ArrayAdapter.SimpleAdapter.BaseAdapter,但是这几个Adapter内部究竟是什么 ...
- SimpleAdapter的使用
SimpleAdapter的使用 SimpleAdapter是一个简单的适配器,该适配器也继承了BaseAdapter,对于布局是固定而言,使用简单适配器开发时非常简单了,由于Simple ...
- 转载《SimpleAdapter的参数说明》
SimpleAdapter的参数说明 第一个参数 表示访问整个android应用程序接口,基本上所有的组件都需要 第二个参数表示生成一个Map(String ,Object)列表选项 第三个参数表示界 ...
- Android学习---ListView的点击事件,simpleAdapter和arrayadapter,SimpleCursoAdapter的原理和使用
如题,本文将介绍 listview的点击事件,simpleAdapter和arrayadapter的原理和使用. 1.ListView的注册点击事件 //注册点击事件 personListView.s ...
- Android开发学习之路-SimpleAdapter源码分析学习
今天在课堂上,老师用到了SimpleAdapter,然后女神在边上问我为什么这个SimpleAdapter不能做到我app那种带有进度条的效果,言语说不清,然后就开始看源代码,发现这个Adapter的 ...
随机推荐
- Memcached源代码分析 - Memcached源代码分析之消息回应(3)
文章列表: <Memcached源代码分析 - Memcached源代码分析之基于Libevent的网络模型(1)> <Memcached源代码分析 - Memcached源代码分析 ...
- struts2自己定义类型转换器
1.1. struts2自己定义类型转换器 1) 自定类型转换类,继承DefaultTypeConverter类 package com.morris.ticket.conversio ...
- (译)Node.js的全局变量
原文标题:Global Variables in Node.js 原文链接:http://www.hacksparrow.com/global-variables-in-node-js.html 你可 ...
- TextBox控件只允许输入出生日期,并验证年龄不得小于18岁
1.Body tag <form id="form1" runat="server"> <div> <asp:Label ID=& ...
- C#面向对象编程基础-喜课堂笔记
**************[5][C#面向对象编程基础]第1讲:类与对象**************** *************2.1.1_类与对象的概念**** ...
- UVa----------1594(Ducci Sequence)
题目: 1594 - Ducci Sequence Asia - Seoul - 2009/2010A Ducci sequence is a sequence of n-tuples of inte ...
- STL之queue(单向队列)
单向队列中的数据是先进先出(First In First Out,FIFO).单向队列一共6个常用函数(front().back().push().pop().empty().size()) #inc ...
- myeclipse 8.6 插件安装之SVN
在这里我要说明一点,myEclipse 8.6的插件安装和之前的版本可能会有一些区别,下面是SVN插件的安装: 1.从官网下载site-1.6.13.zip文件,网址是:subclipse.tigri ...
- Python网络编程——主机字节序和网络字节序之间的相互转换
If you ever need to write a low-level network application, it may be necessary to handle the low-lev ...
- 【转】NP-Hard和NP-Complete的区别
原文来自:http://hi.baidu.com/nuclearspace/item/e0f8a1b777914974254b09f4 对 NP-Hard问题和NP-Complete问题的一个直观的理 ...