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. OUTPUT 在insnert delete update 的神奇功效

    Inserted   deleted  个人理解 应该是两个 临时表   分别存储 变动后的数据集  和  变动前的数据集 使用例子: 1.对于INSERT,可以引用inserted表以查询新行的属性 ...

  2. (转)ThinkPHP find方法 查询一条数据记录

    find() ThinkPHP find() 方法是和 select() 用法类似的一个方法,不同之处 find() 查询出来的始终只有一条数据,即系统自动加上了 LIMIT 1 限制. 当确认查询的 ...

  3. 阿里云OSS存储开发(一)

    Step 1. 初始化一个OSSClient OSSClient是与OSS服务交互的客户端,SDK的OSS操作都是通过OSSClient完成的. 下面代码新建了一个OSSClient: using A ...

  4. 64位操作系统下IIS报“试图加载格式不正确的程序”错误

    缘由:在64位操作系统下IIS发布32位的项目,报“项目依赖的dll无法读取,试图加载格式不正确的程序”错误. 原因:程序集之间的通讯要么全是64位环境下的,要么全是32位环境下的.不能混编访问.不然 ...

  5. OpenGL旋转平移 变换

    #include<gl/glut.h> #include<gl/GL.h> #include<gl/GLU.h> #include<math.h> #i ...

  6. C# 中使用 OpenSSL 的公钥/私钥进行加密和解密

    在C#中进行RSA解密,需要用RSACryptoServiceProvider,但是不支持OpenSSL格式的公钥或者私钥. X509 公钥 -----BEGIN PUBLIC KEY----- MI ...

  7. BZOJ 1688: Disease Manangement (子集枚举)

    Disease Manangement Q - 枚举子集 Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d &a ...

  8. 怎样导入SDWebImage

    Two ways : 方法1:copy all the files into your project. --下载https://github.com/rs/SDWebImage. --把SD项目co ...

  9. iconv内容,convmv文件名,unix2dos,dos2unix文件格式转换,od/cut/wc/dd/diff/uniq/nice/du等命令,linux文件名乱码,文件名,文件内容,vim编码设置

    1.enconv文件名编码转换,比如要将一个GBK编码的文件转换成UTF-8编码,操作如下 enconv -L zh_CN -x UTF-8 filename enconv -L GB2312 -x  ...

  10. 足球3v3心得

    最近常踢球,由于不容易凑人,所以都是最小场:3v3.一开始是凭发育踢,谁的体力好.技术好.速度快.身体壮谁占优.渐渐觉得这样没有意思,就花点时间研究了下足球技战术,总结出几个简单的规律,后来发现这些好 ...