SimpleAdapter:

SimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to)

参数:

1.context:上下文

2.data:Map<String, object>列表,列表要显示的数据,Map列表中的key要与参数”from“中的内容保持一致

3.resource:item的布局文件,这个布局中必须包括参数”to“中定义的控件id

4.from:表示该Map对象的key对应value来生成列表项

5.to:表示来填充的组件 Map对象key对应的资源一依次填充组件 顺序有对应关系

ListView的SimpleAdapter的使用

代码:

 import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter; public class MainActivity extends Activity { private ListView lv; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); List<Map<String, Object>> data = new ArrayList<>(); Map<String, Object> map1 = new HashMap<>();
map1.put("photo", R.drawable.img01);
map1.put("name", "小志");
data.add(map1); Map<String, Object> map2 = new HashMap<>();
map2.put("photo", R.drawable.img02);
map2.put("name", "小志的儿子");
data.add(map2); Map<String, Object> map3 = new HashMap<>();
map3.put("photo", R.drawable.img03);
map3.put("name", "小志的老婆");
data.add(map3); Map<String, Object> map4 = new HashMap<>();
map4.put("photo", R.drawable.img04);
map4.put("name", "萌萌");
data.add(map4); lv = (ListView) findViewById(R.id.lv); lv.setAdapter(new SimpleAdapter(this, data, R.layout.item_view,
new String[] { "photo", "name" }, new int[] { R.id.lv_phono,
R.id.lv_name })); } }

item_view布局文件:

 <?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="wrap_content"
android:orientation="horizontal" > <ImageView
android:id="@+id/lv_phono"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/img01" /> <TextView
android:id="@+id/lv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="名字"
android:textSize="20sp" /> </LinearLayout>
activity_main布局文件:
 <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:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView> </RelativeLayout>

Android开发之ListView-SimpleAdapter的使用的更多相关文章

  1. 【转】Android开发之ListView+EditText-要命的焦点和软键盘问题解决办法

    Android开发之ListView+EditText-要命的焦点和软键盘问题解决办法 [原文链接] 这篇文章完美的解决了我几个月没结论的bug... 感谢热爱分享的技术达人~ 我是怎么走进这个大坑的 ...

  2. android 开发之 ListView 与Adapter 应用实践

    在开发android中,ListView 的应用显得非常频繁,只要需要显示列表展示的应用,可以说是必不可少,下面是记录开发中应用到ListView与Adapter 使用的实例: ListView 所在 ...

  3. Android开发之ListView添加多种布局效果演示

    在这个案例中展示的新闻列表,使用到ListView控件,然后在适配器中添加多种布局效果,这里通过重写BaseAdapter类中的 getViewType()和getItemViewType()来做判断 ...

  4. Android开发之ListView实现不同品种分类分隔栏的效果(非ExpandableListView实现)

    我们有时候会遇到这么一个情况.就是我在一个ListView里面须要显示的东西事实上是有种类之分的.比方我要分冬天,夏天.秋天.春天,然后在这每一个季节以下再去载入各自的条目数据. 还有,比方我们的通讯 ...

  5. Android开发之ListView详解 以及简单的listView优化

    ListView列表视图 最常用的控件之一,使用场景例如:微信,手机QQ等等. android:divider:每个item之间的分割线,可以使用图片或者色值. android:dividerHeig ...

  6. Android开发之ListView设置隔行变色

    public class HLCheckAdapter extends BaseAdapter { private List<HuoLiang> list; private Context ...

  7. Android开发之ListView条目批量选择删除

    ListView实现的列表,假设是可编辑,可删除的,一般都要提供批量删除功能,否则的话,一项一项的删除体验非常不好,也给用户带来了非常大的麻烦. 实现效果图 详细实现代码 select.xml 主布局 ...

  8. android开发之 listview中的item去掉分割线 隐藏分割线

    有三种方法: 1> 设置android:divider="@null" 2> android:divider="#00000000" #000000 ...

  9. 【Android UI】Android开发之View的几种布局方式及实践

    引言 通过前面两篇: Android 开发之旅:又见Hello World! Android 开发之旅:深入分析布局文件&又是“Hello World!” 我们对Android应用程序运行原理 ...

  10. Android开发之Java集合类性能分析

    对于Android开发者来说深入了解Java的集合类很有必要主要是从Collection和Map接口衍生出来的,目前主要提供了List.Set和 Map这三大类的集合,今天Android吧(ard8. ...

随机推荐

  1. html5 全屏滚动活动页学习

    先看几个具体的实例: 1.腾讯娱乐:http://ent.qq.com/zt2014/qqent/h5.htm?from=groupmessage&isappinstalled=0 2.苏宁互 ...

  2. 《WPF程序设计指南》读书笔记——第9章 路由输入事件

    1.使用路由事件 路由事件是一种可以针对元素树中的多个侦听器(而不是仅针对引发该事件的对象)调用处理程序的事件.通俗地说,路由事件会在可视树(逻辑树是其子集)上,上下routed,如果哪个节点上订阅了 ...

  3. 【BZOJ 1821】 [JSOI2010]Group 部落划分 Group

    Description 聪聪研究发现,荒岛野人总是过着群居的生活,但是,并不是整个荒岛上的所有野人都属于同一个部落,野人们总是拉帮结派形成属于自己的部落,不同的部落之间则经常发生争斗.只是,这一切都成 ...

  4. eclipse *.vm 文件,语法高亮

    eclipse *.vm 文件,语法高亮按如下方式不起作用,原因不明.设置文件打开时使用的编辑器General>>Editors>>File Associations 下述方试 ...

  5. 使用pd设计表的 多对多的中间表的设计方式, 有图有真相

    设计多对多表时解决重复问题 目前流行两种设计方式: 方式一 是在中间表中建一个单独的id主键, 与业务表关联的键设置为unique唯一; 干事二: 联合主键的方式, 该方式中间表不会有与业务表无关的主 ...

  6. js学习之函数声明与函数表达式区别[原创]

    作为一名js初学者,与大家分享下.Javascript中有函数声明提升的功能,会优先编译函数声明部分.比如, ff(); function ff(){ alert("hello world. ...

  7. Android Studio 单刷《第一行代码》系列 04 —— Activity 相关

    前情提要(Previously) 本系列将使用 Android Studio 将<第一行代码>(书中讲解案例使用Eclipse)刷一遍,旨在为想入坑 Android 开发,并选择 Andr ...

  8. bnuoj 29368 Check the Identity(栈)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=29368 [题解]:模拟,然后对x,进行枚举,看是否所有都满足条件 [code]: #include ...

  9. gif格式的图片不能存在与包含js目录的路径中?

    如题:gif格式的图片不能存在与包含js目录的路径中?是我的设置问题?还是真不能存在于js目录中. 今天纠结了一下午,某个项目中的效果就是出不来,找了差不多两个半小时... 在D盘新建一个js和jss ...

  10. select count(*)和select count(1)的区别 (转)

    A 一般情况下,Select Count (*)和Select Count(1)两着返回结果是一样的 假如表沒有主键(Primary key), 那么count(1)比count(*)快, 如果有主键 ...