第二章实例:SimpleAdapter结合listview实现列表视图

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实现列表视图的更多相关文章
- 通过游戏学python 3.6 第一季 第二章 实例项目 猜数字游戏--核心代码--猜测次数 可复制直接使用 娱乐 可封装 函数
猜数字游戏--核心代码--猜测次数 #猜数字--核心代码--猜测次数 number=33 amount=3 count=0 while count<=amount: conversion ...
- 第二章实例:ArrayAdapter结合ListView列表视图
package mydefault.packge; import com.example.codeview.R; import android.app.Activity; import android ...
- 第二章实例:ActionBar结合Fragment显示
package tab.test; import com.example.actionbar_tab.R; import android.app.ActionBar; import android.a ...
- 第二章实例:Android窗口菜单显示
package test.main.cls; import com.example.popupwindow.R; import android.app.Activity; import android ...
- 第二章实例:动态生成View控件例子---小球跟随手指滑动
package mydefault.packge; import android.app.Activity; import android.content.Context; import androi ...
- 使用SimpleAdapter创建ListView
通过ArrayAdapter实现Adapter虽然简单.易用,但ArrayAdapter的功能比较有限.它的每个列表只能是TextView.如果开发者需呀实现更复杂的列表项,则可以考虑使用Simple ...
- HTML第二章:列表,表格,媒体元素
第二章:列表,表格,媒体元素 列表:有三种,有序列表,无序列表,定义列表 1.有序列表:<ol></ol> 列表项:<li></li&g ...
- 滚动视图、列表视图[ListView、SimpleAdapter类]
滚动视图 <ScrollView android: layout_width="fill_parent" android: layout_height="fill_ ...
- [ABP教程]第二章 图书列表页面
Web应用程序开发教程 - 第二章: 图书列表页面 关于本教程 在本系列教程中, 你将构建一个名为 Acme.BookStore 的用于管理书籍及其作者列表的基于ABP的应用程序. 它是使用以下技术开 ...
随机推荐
- VS2012 拆分视图按钮不见,代码,设计
工具--选项--HTML设计器 然后重启就有了.
- Java坑一
public class Test { public static void main(String[] args) { Integer a = 12; Integer b = 12; System. ...
- Direct2D 几何图形绘制基础
之前说过,D2D主要为了绘制有三种类型的数据:几何图形,图片,文字.这几种对象也叫做资源,资源就是要D2D流水线中要被加工的对象. 几何图形包括: 简单几何图形 直线,DrawLine,由起点和终点构 ...
- oracle 查询重复数据
SELECT * FROM td_attrval_group WHERE parent_attrval_id IN(SELECT parent_attrval_id FROM td_attrval_g ...
- css使用技巧
1) 网站上经常会出现用户输入一大段字符和字母以至于文字无法正常折行,把版式破坏,这样我们就要参考以下样式:word-wrap:break-word; overflow:hidden; 当然必须得有宽 ...
- 连接oracle数据库出现:ORA-12505,TNS:listener does not currently know of SID given in connect descriptor
Java使用 jdbc:oracle:thin:@11.1.0.14:1521:orcl 连接oracle数据库出现: ORA-12505,TNS:listener does not currentl ...
- INSERTION_SORT插入排序C++实现
大家好,我是小鸭酱,博客地址为:http://www.cnblogs.com/xiaoyajiang 以下用C++实现插入排序的升序和降序排序 算法来自<算法导论> #include< ...
- SPI总线的4种工作模式
spi总线的4种工作模式 0 to 4 modes SPI接口的全称是"Serial Peripheral Interface",意为串行外围接口,是Motorola首先在其MC6 ...
- keil TEA
http://bbs.mydigit.cn/read.php?tid=545086 #include "reg52.h" void send_char(unsigned char ...
- 杀死MySQL的连接
命令 kill 执行线程号 C# 执行杀死指定的连接 1 强制Kill掉 internal protected void KillConnection(MySqlConnection c) { i ...