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. Entity Framework中datetime2 to datetime转换错误

    datetime2 to datetime 报错. 因为EF中,DATETIME类型默认是datetime2,数据库默认是datetime. 解决方案: 1.改数据库字段类型为datetime2 2. ...

  2. Oracle - 使用序列+触发器实现主键自增长

    Oracle中的自增,不如Sql server那般方便. --.创建序列 CREATE SEQUENCE "TABLE_NAME"."SQ_NAME" MINV ...

  3. 使用bootstrapvalidator的remote验证经验

    这里需要说一下,bootstrapvalidator的帮助文档写的比较简单,对于remote验证器的说明更是如此,在经历多方测试之后才明白如何使用这个验证器. 一个典型的ajax验证代码如下: 服务端 ...

  4. C#避免过长的IF和Switch分支的方法

    C#避免过长的IF和Switch分支的方法 1.最蠢形态 //很丑有没有! //这个分支要是一两个还是可以接受的 class Program { static void Main(string[] a ...

  5. memcmp()直接比较两个数组的大小

    两个字符数组可以用strcmp()比较大小.两个整数数组也有个函数memcmp()可以比较大小,和strcmp()的返回值一样的. 头文件#include<cstring> / #incl ...

  6. Orchard开源ASP.NET MVC CMS简介

    项目简介: Orchard CMS 是一个免费的开放源代码内容管理系统,让用户可在 Microsoft ASP.NET MVC 平台上快速创建网站.它基于灵活的扩展性框架构建,使开发人员和定制人员可通 ...

  7. base64自定义编码表 php版本

    在一次接口对接中,要用到base64自定义编码表来进行编码和解码,从网上搜索了一下,讲原理的比较多也比较透彻,提供的编码的例子但是没有解码的,以下是自己实现的一个base64自定义字典解码的例子,比较 ...

  8. 快速下单!简化EcStore的购物结算流程

    EcStore拥有完善的购物车功能,方便顾客浏览挑选商品,但是在提交订单时必须要求用户先登录注册 如果是未注册用户还多出一个注册用户的步骤这些多出来的步骤和操作会影响购物下单的流畅性,降低了用户购物下 ...

  9. tp中u方法的使用

    自学的时候都没怎么使用过该方法,现在刚进入一个新公司参加项目.发现这个方法用的很多,所以记录下来防止以后忘了. U方法用于完成对URL地址的组装,特点在于可以自动根据当前的URL模式和设置生成对应的U ...

  10. nginx+keepalived+tomcat之具体配置档

    前沿知识点: nginx负责负载均衡(反向代理) msm(memcached session manager)负责缓存会话信息,从而实现会话保持 所需包: nginx和memcached采用最新稳定版 ...