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. 使用WebUploader使用,及使用后测试横拍或竖拍图片图片方向不对等解决方案

    WebUploader是由Baidu WebFE(FEX)团队开发的一个简单的以HTML5为主,FLASH为辅的现代文件上传组件.在现代的浏览器里面能充分发挥HTML5的优势,同时又不摒弃主流IE浏览 ...

  2. jquery动画总结

    基本动画 show() //直接显示元素,没有动画 show(speed, [callback]) //有动画,有回调函数 hide() //直接隐藏元素,没有动画 hide(speed, [call ...

  3. Deep Learning学习随记(一)稀疏自编码器

    最近开始看Deep Learning,随手记点,方便以后查看. 主要参考资料是Stanford 教授 Andrew Ng 的 Deep Learning 教程讲义:http://deeplearnin ...

  4. Swift - 22 - 循环结构

    //: Playground - noun: a place where people can play import UIKit // for-in for i in -99...99 { i * ...

  5. 使用第三方SDK出现: duplicate symbol _llvm.cmdline in:

    如果是同一个静态库中的文件链接的时候有冲突,可能是这个静态库不支持模拟器,真机运行就好了. 或者可以使用xcode7的虚拟机跑也是没问题的. duplicate symbol _llvm.cmdlin ...

  6. 使用less函数实现不同背景的CSS样式

    今天在公司遇到一个比较特殊的需求,需要完成这样的布局,如下图: 每一个块的背景需要不同,而其他都是相同的,这时候就应该把背景提出来单独写成一个CSS样式类. 那么问题来了,有四个不同的背景需要写4个基 ...

  7. [转]Delphi中进行延时的4种方法

    1.挂起,不占CPU sleep 2.不挂起,占cpu procedure Delay(msecs:integer); var FirstTickCount:longint; begin FirstT ...

  8. javascript基础学习(十五)

    javascript之cookie 学习要点: cookie介绍 创建与获取cookie cookie的编码 cookie的生存期 cookie的路径 cookie的domain cookie的sec ...

  9. 使用EF实现数据库的增删改查

    EF的使用步骤:(1)将EF添加到项目:在Model右击添加新建项找到ADO.NET实体数据模型,接着…(2)实现数据库的增删改查查询(因为在Model中已经添加EF实体了,所以就可以在Control ...

  10. springmvc问题汇总

    1.  IncompatibleClassChangeError in spring mvc Failed to read candidate component class.......       ...