SimpleAdapter是扩展性最好的适配器,可以定义各种你想要的布局。

构造方法:

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

  参数context:上下文,比如this。关联SimpleAdapter运行的视图上下文

  参数data:Map列表,列表要显示的数据,这部分需要自己实现,类型要与上面的一致,每条项目要与from中指定条目一致

  参数resource:ListView单项布局文件的Id,这个布局就是你自定义的布局了,你想显示什么样子的布局都在这个布局中。这个布局中必须包括了to中定义的控件id

  参数 from:一个被添加到Map上关联每一个项目列名称的列表,数组里面是列名称

  参数 to:是一个int数组,数组里面的id是自定义布局中各个控件的id,需要与上面的from对应

首先来看效果图:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" > <ListView
android:id="@+id/lv"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> </RelativeLayout>

activity_main.xml

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" > <ImageView
android:id="@+id/left_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img01" /> <TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="@id/left_img"
android:text="锁定手机"
android:textSize="24sp" /> <ImageView
android:id="@+id/right_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/content"
android:layout_below="@id/left_img"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="简介键尖技术男女生就是就是计算机技术就是就是解决"/> </RelativeLayout>

item_layout

 public class MainActivity extends Activity {

     ListView lv;

     // 数据源
int[] leftImgs = { R.drawable.img01, R.drawable.img02, R.drawable.img03,
R.drawable.img04, R.drawable.img05, R.drawable.img06, };
String[] titles = { "锁定手机", "手机杀毒", "解锁手机", "手机上网", "我的文档", "手机导航" };
int rightImgs = R.drawable.ic_launcher; String content = "专门处理锁定手机相关功能,我是采用构造方法的守护神是计算机技术三角肌松解术世尊计上计"; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); lv = (ListView) findViewById(R.id.lv); List<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>();
for (int i = 0; i < 6; i++) { HashMap<String, Object> map = new HashMap<String, Object>();
map.put("leftImg", leftImgs[i]);
map.put("title", titles[i]);
map.put("rightImg", rightImgs);
map.put("content", content); data.add(map);
} SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, data,
R.layout.item_phone, new String[] { "leftImg", "title",
"rightImg", "content" }, new int[] { R.id.left_img,
R.id.title, R.id.right_img, R.id.content }); lv.setAdapter(adapter);
} }

MainActivity.java

Android SimpleAdapter ListView (锁定手机,解锁手机的列表)的更多相关文章

  1. 如何在Android的ListView中构建CheckBox和RadioButton列表(支持单选和多选的投票项目示例)

    引言 我们在android的APP开发中有时候会碰到提供一个选项列表供用户选择的需求,如在投票类型的项目中,我们提供一些主题给用户选择,每个主题有若干选项,用户对这些主题的选项进行选择,然后提交. 本 ...

  2. 小米手机解锁bootload教程及常见问题

    小米手机解锁bl需要在官网提交申请,然后电脑解锁,具体步骤如下: 1.首先需要注册一个小米账号,并登陆. 2.到官网解锁网页提交申请:http://www.miui.com/unlock/index. ...

  3. android视频录制、另一部手机实时观看方案

    最近调研android视频录制.另一部手机实时观看,大致有以下几种思路. 1. android手机充当服务器,使用NanoHTTPD充当服务器,另一部手机或者pc通过输入http://手机的ip:80 ...

  4. Android 本地tomcat服务器接收处理手机上传的数据之案例演示

    上一篇:Android 本地tomcat服务器接收处理手机上传的数据之环境搭建     本篇基于上一篇搭建的服务器端环境,具体介绍Android真机上传数据到tomcat服务器的交互过程   场景:A ...

  5. windows phone 手机解锁失败问题

    1.使用 VS 2015  自带的  Windows Phone Developer Registration (8.1) 工具, 解锁手机. 总是提示 日期和时间错误. 解决办法,  有2个 1.打 ...

  6. iPhone手机解锁效果&&自定义滚动条&&拖拽--Clone&&窗口拖拽(改变大小/最小化/最大化/还原/关闭)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. 如何获得Android手机的软件安装列表

    Android的PackageManager类用于检索目前安装在设备上的应用软件包的信息.你可以通过调用getpackagemanager()得到PackageManager类的一个实例.对查询和操作 ...

  8. android 查看手机运行的进程列表

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...

  9. java攻城狮之路(Android篇)--ListView与ContentProvider

    一.ListView 1.三种Adapter构建ListView ListView添加条目的时候, 可以使用setAdapter(ListAdapter)方法, 常用的ListAdapter有三种 B ...

随机推荐

  1. (转)PHP中构造函数和析构函数解析

    --http://www.jb51.net/article/56047.htm 构造函数 void __construct ([ mixed $args [, $... ]] ) PHP 5 允行开发 ...

  2. ASP.NET Core中使用Razor视图引擎渲染视图为字符串

    一.前言 在有些项目需求上或许需要根据模板生产静态页面,那么你一样可以用Razor语法去直接解析你的页面从而把解析的页面生成静态页,这样的使用场景很多,不限于生成静态页面,视图引擎为我们提供了模型到视 ...

  3. Hibernate 主键生成策略

    表示符生成器 描述 Increment 由hibernate自动以递增的方式生成表识符,每次增量为1 Identity 由底层数据库生成表识符.条件是数据库支持自动增长数据类型. Sequence H ...

  4. 在SpringMVC框架下建立Web项目时web.xml到底该写些什么呢?

    刚刚初学Spring MVC,却连一个简单的helloworld都搞的懵懵懂懂的,配置文件搞不清,各种文件之间的逻辑关系也不懂,连续看了好些日子的Spring MVC了,今天终于下定决心,每天记录一点 ...

  5. 将对象保存至文件——CArchive

    CArchive允许以一个二进制的形式保存一个对象的复杂网络,也可以再次装载它们,在内存中重新构造,这一过程叫作串行化/序列化(Serialization),简单的说,CArchive与CFile配合 ...

  6. UVA 10254 - The Priest Mathematician (dp | 汉诺塔 | 找规律 | 大数)

    本文出自   http://blog.csdn.net/shuangde800 题目点击打开链接 题意: 汉诺塔游戏请看 百度百科 正常的汉诺塔游戏是只有3个柱子,并且如果有n个圆盘,至少需要2^n- ...

  7. PHP迭代器

    在所有语言中,所有迭代器都必须具有如下4想功能: 1.回滚迭代器到第一个元素 2.潜行到下一个元素 3.获取当前元素 4.验证是否到最后一个元素了 在PHP中我我们可以通过实现iterator来实现迭 ...

  8. Python正则表达式+自创口诀

    重新学习了Python正则表达式,看了一些很好的学习博客,向大家推荐这个. 感谢作者@AstralWind 博客地址:http://www.cnblogs.com/huxi/archive/2010/ ...

  9. Spark Executor Driver资源调度小结【转】

    一.引子 在Worker Actor中,每次LaunchExecutor会创建一个CoarseGrainedExecutorBackend进程,Executor和CoarseGrainedExecut ...

  10. 如何使用Instruments诊断App(Swift版):起步-b

    无论你写过许多iOS应用,还是刚刚开始你的第一个应用,毫无疑问,你都会想出一些新点子,或者想去弄明白你该怎么做,来让你的app变得更好. 除去添加新特性来优化你的应用,有一件事是所有好的开发者都回去做 ...