package test.simpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import com.example.simpleadapters.R; import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter; public class ListContent extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.list_content);
//-----------------------------------------
//为simpleAdapter构造数据
String []title = {"排山倒海","葵花点穴手","如来神掌"};
String []tips = {"威力巨大给对手造成巨大内伤,即使对手逃逸也会无疾而终","短暂制瘫对方,瞬间废除对手活动能力,即可为所欲为","有效杀伤力达几百米寸草不生,但灰尘太大不环保"};
int []icon = {R.drawable.psdh,R.drawable.khdxs,R.drawable.rlsz};
String []time ={"14:30","14:20","14:10"};
//---------------------------------------
//构造玩上述数据后,开始构造它们xml布局
//---------------------------------------
//将数据打包成MAP对象
List<Map<String,Object>> map_content = new ArrayList<Map<String,Object>>();
for(int i = 0; i < title.length;i++){
Map map = new HashMap<String, Object>();
//打包方式 key value键值对形式
map.put("title", title[i]);
map.put("tips", tips[i]);
map.put("icon", icon[i]);
map.put("time", time[i]);
//------------------------------------
map_content.add(map);
}
//----------------------------------------
//生成xml布局资源ID引用 int []xmlres = {R.id.avatar,R.id.list_title,R.id.list_tips,R.id.list_time};
//生成键素组
String []mapkey = {"icon","title","tips","time"};//与上面的xmlres数组的资源ID对应
//map对象构造完毕,接下来生成simpleAdapter对象
//构造simpleAdapter所需参数说明:context窗口对象,盛装map的list,列表栏目布局资源ID的引用,list中的map中对应的键名称,键名称对应的控件资源ID;
SimpleAdapter sAdapter = new SimpleAdapter(ListContent.this, map_content, R.layout.simple_adapter_list, mapkey, xmlres);
ListView list = (ListView)findViewById(R.id.main_list);
list.setAdapter(sAdapter);//设置资源 } }

xml:

//list_content
<?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="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/main_list"
android:layout_width="match_parent"
android:layout_height="match_parent"> </ListView> </LinearLayout>
//simple_adapter
<?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="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/avatar"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_weight="0.7"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/list_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"/>
<TextView
android:id="@+id/list_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.8"/>
</LinearLayout>
<TextView
android:id="@+id/list_tips"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout> </LinearLayout>

最新文章

  1. iOS 常用三方类库整理
  2. 【原】iphone6来了,我该做点什么(兼容iphone6的方法)
  3. vld使用
  4. 【ZJOI2004】嗅探器
  5. [Aaronyang] 写给自己的WPF4.5 笔记22 [3d交互与动画 3/4]
  6. Quartz.Net 配置模板范例
  7. 浅谈C#随机数发生器
  8. 微软下一代云环境Web开发框架ASP.NET vNext预览
  9. 转: cmd和amd的区别
  10. C++中的向上类型转换和向下类型转换
  11. Mac环境下.Net开发
  12. Elasticsearch安装详解
  13. MQTT客户端库-Paho GO
  14. 关于MarkDown里的图片问题
  15. CNUTCon2017全球运维技术大会(持续更新中) - 斯达克学院 - 实战驱动的 IT 教育平台 - Powered By EduSoho
  16. 0x01 Spring Cloud 概述
  17. [Canvas]更多的球
  18. Linux 使用系统ISO制作yum源
  19. Google.ProtocolBuffers.dll 之.Net应用(一)
  20. node(4)express 框架 EJS模板,cookie, session的学习

热门文章

  1. HTML5-常见的事件- contextmenu 事件
  2. javascript正则简单入门
  3. .net程序员转战android第三篇---登录模块之静态登录
  4. 上拉、下拉UITableView,交互式 模态弹出(自定义弹出动画)
  5. Memcache入门知识
  6. php对数组中指定键值排序
  7. Lucene学习总结之七:Lucene搜索过程解析
  8. sitemap.xml 静态和动态生成页面 shopnc二次开发 动态生成sitemap.xml
  9. android启动activity文本框不获得焦点
  10. yii2中的url美化