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. 使用分部类给Models添加验证Attributes

    网摘1: 在使用Entity Framework 的Database frist或model first时,直接加attribute到modle类上是太现实也不合理的,因为model类是自动生成的,重 ...

  2. 表格细边框 并且CSS3加圆角

    .YJ table{width:625px;height:860px;text-align:center;overflow:hidden; background:#fff;border-radius: ...

  3. 【转】JS函数的定义与调用方法

    JS函数调用的四种方法:方法调用模式,函数调用模式,构造器调用模式,apply,call调用模式 1.方法调用模式:先定义一个对象,然后在对象的属性中定义方法,通过myobject.property来 ...

  4. 转载 C# BindingSource

    1.引言 BindingSource组件是数据源和控件间的一座桥,同时提供了大量的API和Event供我们使用.使用这些API我们可以将Code与各种具体类型数据源进行解耦:使用这些Event我们可以 ...

  5. JS判断设备终端(PC,iPad,iPhone,android,winPhone)和浏览器

    JS判断设备终端(PC,iPad,iPhone,android,winPhone)和浏览器 var ua = navigator.userAgent; var browser = {}, weixin ...

  6. 转发 PHP 资料(一)

    WebShell隐藏思路.webshell磁盘读写动态检测.webshell沙箱动态检测(2)   作为WebShell检测.CMS修复.WebShell攻防研究学习的第二篇文章 本文旨在研究Webs ...

  7. PHP 跨域写cookie

    实际工作中,类似这样的要求很多,比如说,我们有两个域名,我们想实现在一个域名登录后,能自动完成另一个域名的登录,也就是PASSPORT的功能. 我只写一个大概,为了测试的方便,先编辑hosts文件,加 ...

  8. Spark Streaming揭秘 Day11 Receiver Tracker的具体实现

    Spark Streaming揭秘 Day11 Receiver Tracker的具体实现 ReceiverTracker是运行在Driver上Receiver管理程序,今天让我们深入学习一下. 核心 ...

  9. nginx+php-fpm 502 bad gateway

    输出日志配置: http://blog.csdn.net/wzy_1988/article/details/8486888 解决方案: http://www.cnblogs.com/jackluo/p ...

  10. SharpDeveloeper开发ASP.NET MVC汗流浃背

    今天好不容易休息了一天,上网狂了一圈,突然想起了以前的一个轻量级的开发工具"SharpDeveloper",于是就下载试着来开发一下ASP.NET,但是老魏没有想到的是,虽然官方提 ...