1.MainActivity.java

public class MainActivity extends Activity {
private ListView listView;
private SimpleAdapter simp_adapter;
private List<Map<String, Object>> dataList; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); /* 1.context:上下文对象
2.data:数据源(List<? extents Map<String,? >> data)一个Map所组成的List集合.
每个Map都相应ListView列表中的一行.
每个Map(键-值对)中的键必须包括全部在from中所指定的键
3.resource:列表项的布局文件ID
4.from:Map中的键名
5.to:绑定数据视图中的ID,与FROM成相应关系
*/ listView = (ListView)findViewById(R.id.listView);
//1.新建适配器
dataList = new ArrayList<Map<String,Object>>();
//2.适配器载入数据源
simp_adapter = new SimpleAdapter(this, getData(),R.layout.item,
new String[] {"image","text"}, new int[]{R.id.image,R.id.text});
//视图载入适配器
listView.setAdapter(simp_adapter);
} public List<Map<String, Object>> getData(){
for(int i = 0;i<20;i++){
Map<String, Object> map = new HashMap<String, Object>();
map.put("image", R.drawable.ic_launcher);
map.put("text", "Just a Demo."+i);
dataList.add(map); } return dataList;
}
}

2.activity_main.xml

<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" > <ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView> </RelativeLayout>

3.item.xml

<?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/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:src="@drawable/ic_launcher" /> <TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Demo"
android:textColor="#000000"
android:textSize="20sp" /> </LinearLayout>

效果图:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2hhb3NoZW55dXRvdQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

Android SimpleAdapter的更多相关文章

  1. Android SimpleAdapter源码详解

    一直没认真看过android的源码,也不太敢看,稀里糊涂也敲了一年的代码,现在想好好学习了,就把常用的源码都看了一下,小伙伴们来涨姿势吧,有错误的地方,直接指出,我脸厚不怕丢人.来吧. 刚开始学and ...

  2. Android SimpleAdapter ListView (锁定手机,解锁手机的列表)

    SimpleAdapter是扩展性最好的适配器,可以定义各种你想要的布局. 构造方法: SimpleAdapter(Context context, List<? extends Map< ...

  3. Android SimpleAdapter GridView (网格图片点击放大显示)

    GridView网格视图 GridView网格视图是按照行,列分布的方式来显示多个组件,通常用于显示图片或是图标等,在使用网格视图时,首先需要要在屏幕上添加GridView组件. 常用属性: 1. a ...

  4. Android SimpleAdapter的参数

    1.作用是ArrayList和 ListView的桥梁.这个ArrayList里边的每一项都是一个Map<String,?>类型.       ArrayList当中的每一项 Map对象都 ...

  5. Android SimpleAdapter ViewBinder

  6. 【起航计划 003】2015 起航计划 Android APIDemo的魔鬼步伐 02 SimpleAdapter,ListActivity,PackageManager参考

    01 API Demos ApiDemos 详细介绍了Android平台主要的 API,android 5.0主要包括下图几个大类,涵盖了数百api示例:

  7. android 组件使用()

    程序入口点 类似于win32程序里的WinMain函数,Android自然也有它的程序入口点.它通过在AndroidManifest.xml文件中配置来指明,可以看到名为NotesList的activ ...

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

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

  9. Android日记-SimpleAdapter和BaseAdapter

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

随机推荐

  1. 海思平台服务器版软件V15.2产品发布

    深度操作系统海思平台服务器版软件是武汉深之度科技有限公司发布的针对华为海思平台的TaiShan系列服务器发布的企业级服务器操作系统软件产品,主要面向企业级服务器应用场景,为用户在国产化平台上提供更具可 ...

  2. Android圆形图片不求人,自定义View实现(BitmapShader使用)

    在很多APP当中,圆形的图片是必不可少的元素,美观大方.本文将带领读者去实现一个圆形图片自定View,力求只用一个Java类来完成这件事情. 一.先上效果图 二.实现思路 在定义View 的onMea ...

  3. Impala管理

    这里, 以后更新. Impala的安装(含使用CM安装 和 手动安装)(图文详解) 可以通过下面的链接来访问Impala的监护管理页面: • 查看StateStore – http://node1:2 ...

  4. 手机端使用rem的适配

    <html> <body> <!-- http://www.w3cfuns.com/notes/29143/79dafb7c07f6865f435af641869d312 ...

  5. 微信小程序---app.json中设置背景色不生效解决办法

    按照官方文档的说明,backgroundColor应该可以设置窗口的背景色. "window":{ "backgroundTextStyle":"li ...

  6. newgrp---将当前登录用户临时加入到已有的组中

    Linux中的newgrp命令主要是将当前登录用户临时加入到已有的组中,用法如下: [linuxidc@localhost etc]$ newgrp grptest 上面命令的含义是将用户linuxi ...

  7. 解决xorm逆向mssql报datetime2不兼容的异常错误

    xorm作为golang开发者的一大利器,深受大家的喜爱,可是最近在逆向mssql的时候,报了这么一个错误: 最后找了半天发现xorm没有预置DateTime2类型,经过几番折腾,在xorm源码的en ...

  8. 论Node在构建超媒体API中的作用

    论Node在构建超媒体API中的作用 作者:chszs,转载需注明. 博客主页:http://blog.csdn.net/chszs 超媒体即Hypermedia,是一种採用非线性网状结构对块状多媒体 ...

  9. erlang虚拟机代码运行原理

    erlang是开源的,非常多人都研究过源码.可是.从erlang代码到c代码.这是个不小的跨度.并且代码也比較复杂. 所以这里,我利用一些时间,整理下erlang代码的运行过程.从erlang代码编译 ...

  10. struts2中action手动获取參数

    struts2中action手动获取Session,jsp页面參数 1. ActionContext 在Struts2开发中,除了将请求參数自己主动设置到Action的字段中,我们往往也须要在Acti ...