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>

第二章实例:SimpleAdapter结合listview实现列表视图的更多相关文章

  1. 通过游戏学python 3.6 第一季 第二章 实例项目 猜数字游戏--核心代码--猜测次数 可复制直接使用 娱乐 可封装 函数

      猜数字游戏--核心代码--猜测次数   #猜数字--核心代码--猜测次数 number=33 amount=3 count=0 while count<=amount: conversion ...

  2. 第二章实例:ArrayAdapter结合ListView列表视图

    package mydefault.packge; import com.example.codeview.R; import android.app.Activity; import android ...

  3. 第二章实例:ActionBar结合Fragment显示

    package tab.test; import com.example.actionbar_tab.R; import android.app.ActionBar; import android.a ...

  4. 第二章实例:Android窗口菜单显示

    package test.main.cls; import com.example.popupwindow.R; import android.app.Activity; import android ...

  5. 第二章实例:动态生成View控件例子---小球跟随手指滑动

    package mydefault.packge; import android.app.Activity; import android.content.Context; import androi ...

  6. 使用SimpleAdapter创建ListView

    通过ArrayAdapter实现Adapter虽然简单.易用,但ArrayAdapter的功能比较有限.它的每个列表只能是TextView.如果开发者需呀实现更复杂的列表项,则可以考虑使用Simple ...

  7. HTML第二章:列表,表格,媒体元素

    第二章:列表,表格,媒体元素 列表:有三种,有序列表,无序列表,定义列表 1.有序列表:<ol></ol>            列表项:<li></li&g ...

  8. 滚动视图、列表视图[ListView、SimpleAdapter类]

    滚动视图 <ScrollView android: layout_width="fill_parent" android: layout_height="fill_ ...

  9. [ABP教程]第二章 图书列表页面

    Web应用程序开发教程 - 第二章: 图书列表页面 关于本教程 在本系列教程中, 你将构建一个名为 Acme.BookStore 的用于管理书籍及其作者列表的基于ABP的应用程序. 它是使用以下技术开 ...

随机推荐

  1. Android--------解决ScrollView中嵌套ExpandableListView显示不全的问题

    ##***Scrollview和ExpandableListView嵌套显示不全*** - 当我们将ExpandableListView嵌套在Scrollview之中时,我们必须要确保我们的不居中Ex ...

  2. codeforces 340E Iahub and Permutations(错排or容斥)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Iahub and Permutations Iahub is so happy ...

  3. (原)配置vs2013使用intel的IPP库

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5473890.html 参考网址: https://software.intel.com/en-us/n ...

  4. (原)Understand中查看函数调用关系

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/4994551.html 1. 选中某函数,如_tmain,右键“Graphical Views——Cal ...

  5. 利用raspberry pi搭建typecho笔记(三) typecho nginx sqlite FAQ

    前言 这是一个汇总文,用来总结我在整个配置过程中遇到的各种问题.因为我在解决这些问题的过程中发现,typecho被部署在这种需要完全自己配置的平台上的情况是比较少的,相关的资料也比较少,所以我的解决过 ...

  6. Mysql基础教程——mysql之一

    教程列表:http://www.dxzy163.com/view/index7627.html 41 存储过程 40 全文索引与停止词 39 索引的管 38 索引概念 37 数据库备份与恢复 36 事 ...

  7. 老了,问题定位难了,xml编码解析

    同样一个程序,在A机器好用,在B机器不好用,怀疑过jdk版本位数问题,怀疑过其他. 最后,突然发现出错的全是xml中文,想到是不是编码问题,一看环境变量果真一个gbk,一个utf-8,再一看 程序,没 ...

  8. 【MVC4 之 ViewData ViewBag TempData】

    ViewData (一个字典集合类型):传入的key必须是string类型,可以保存任意对象信息,特点:它只会存在这次的HTTP的要求中而已,并不像session可以将数据带到下一个Http要求. V ...

  9. C语言的本质(33)——GCC编译器入门

    GCC(GNU CompilerCollection,GNU编译器套装),是由 GNU 开发的编程语言编译器.它是以GPL许可证所发行的自由软件,也是 GNU计划的关键部分.GCC原本作为GNU操作系 ...

  10. WordPress SEO ☞ WordPress网站终极优化指南

    原文地址:http://www.eastdesign.net/wordpress-seo/ 最新消息,东方设计学院 WordPress SEO 系列视频教程正在持续更新中,目前为了不至于让视频传播过于 ...