第二章实例: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的应用程序. 它是使用以下技术开 ...
随机推荐
- 在本地调试微信项目(C#)
之前一人负责微信的项目,那时2014年LZ还没毕业..啥都不懂,为此特别感谢@SZW,没有你的框架,我可能都无从下手 当时做项目最麻烦的就是调试,因为很多页面都要使用 网页授权获取用户信息 在电脑上打 ...
- asp.net缓存(三)
Asp.net应用程序数据缓存 System.Web.Caching 命名空间提供用于缓存服务器上常用数据的类.此命名空间包括 Cache 类,该类是一个字典,您可以在其中存储任意数据对象,如哈希表和 ...
- Memcached内存管理模型分析
Memcached 是一个高性能的分布式内存对象缓存系统,它通过在内存中缓存数据和对象来减少读取数据库的次数,从而减轻RDBMS的负担,提高服务的速度.提升可扩展性.本文将基于memcached1.4 ...
- CDZSC_2015寒假新人(1)——基础 h
Description Ignatius was born in a leap year, so he want to know when he could hold his birthday par ...
- java开发webservice
第一部分:相关下载配置 1.开发环境 eclipse-jee-mars-2-win32-x86_64.zip http://www.eclipse.org/downloads/index-pac ...
- EditText判断用户输入完成,然后进行操作解决方案
private Timer timer = new Timer(); private final long DELAY = 1000; // in ms EditText editTextStop = ...
- Zend Studio 文件头和方法注释设置
在zend studio中选择窗口->首选项->PHP–>编辑器 –>模板 –>新建 然后添加 funinfo或fileinfo 模板代码根据下边定义的COPY过去就可以 ...
- ni
坚强歌词 马天宇 - 坚强 天使的翅膀挥动着的光芒一路走来学会了坚强每一次你努力认真的模样让我很欣赏 雨天的路上会有一缕阳光温暖被淋湿的希望再小的河也能汇成海洋让我去远航 一路上陪伴我的目光是最感动的 ...
- BC 65 game
主持人一直某个数字在1到n范围,假设甲乙已经知道,甲先猜乙后,都采用最优策略,主持人说偏大还是偏小,不断缩小范围,问最后乙能会获胜的X的取值的个数. 如果n为奇数,那么仅当x=n/2乙必然获胜,若为奇 ...
- SQL Server索引设计 <第五篇>
SQL Server索引的设计主要考虑因素如下: 检查WHERE条件和连接条件列: 使用窄索引: 检查列的选择性: 检查列的数据类型: 考虑列顺序: 考虑索引类型(聚集索引OR非聚集索引): 一.检查 ...