利用SimpleExpandableListAdapter为ExpandableListActivity提供数据
首先MainActivity继承自ExpandableListActivity,其中的声明如下:
setContentView(R.layout.expandmain);
//定义一个:List,该List对象为一级条目提供数据
List<Map<String,String>> parents = new ArrayList<Map<String,String>>();
Map<String,String> parent1 = new HashMap<String,String>();
parent1.put("group", "parent1");
Map<String,String> parent2 = new HashMap<String,String>();
parent2.put("group", "parent2");
parents.add(parent1);
parents.add(parent2);
//定义一个List,该List对象为第一个一级条目提供数据
List<Map<String,String>> child1 = new ArrayList<Map<String,String>>();
Map<String,String> childData1 = new HashMap<String,String>();
childData1.put("child", "child1Data1");
Map<String,String> childData2 = new HashMap<String,String>();
childData2.put("child", "child1Data2");
child1.add(childData1);
child1.add(childData2);
//定义一个List,该List对象为第二个一级条目提供数据
List<Map<String,String>> child2 = new ArrayList<Map<String,String>>();
Map<String,String> childData3 = new HashMap<String,String>();
childData3.put("child", "child1Data3");
Map<String,String> childData4 = new HashMap<String,String>();
childData4.put("child", "child1Data4");
child2.add(childData3);
child2.add(childData4);
//生成一个List,该List对象用来存储所有的二级条目的数据
List<List<Map<String,String>>> childs = new ArrayList<List<Map<String,String>>>();
childs.add(child1);
childs.add(child2);
//context
//一级条目的数据
//用来设置一级条目样式的布局文件
//指定一级条目数据的key
//指定一级条目显示控件的ID
//指定二级条目的数据
//用来设置二级条目的布局文件
//指定二级条目数据的key
//指定二级条目数据显示控件的ID
SimpleExpandableListAdapter sela = new SimpleExpandableListAdapter(this, parents, R.layout.parent, new String[]{"group"}, new int[] {R.id.parentTo}, childs, R.layout.child, new String[]{"child"},new int[]{R.id.childTo});
//将SimpleExpandableListAdapter设置给当前的ExpandableListActivity
setListAdapter(sela);
其中expandmain.xml文件中的内容
<?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" >
<ExpandableListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"/>
</LinearLayout>
parent.xml文件的内容如下:
<?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" >
<TextView android:id="@+id/parentTo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20px"
android:textSize="26sp"
android:text="No data"/>
</LinearLayout>
child.xml文件中的内容如下:
<?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" >
<TextView
android:id="@+id/childTo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20px"
android:textSize="20sp"
android:text="No data" />
</LinearLayout>
利用SimpleExpandableListAdapter为ExpandableListActivity提供数据的更多相关文章
- 如何做好 Android 端音视频测试?
在用户眼中,优秀的音视频产品应该具有清晰.低延时.流畅.秒开.抗丢包.高音效等特征.为了满足用户以上要求,网易云信的工程师通过自建源站,在SDK端为了适应网络优化进行QoS优化,对视频编码器进行优化, ...
- ExpandableListActivity的基本使用方法 ,SimpleExpandableListAdapter的基本使用方法
activity_main.xml: <ExpandableListView android:id="@id/android:list" android:layout_wid ...
- android之ExpandableListActivity
MainActivity.java package com.example.mars_2300_expandablelist; import java.util.ArrayList; import j ...
- Android ExpandableListActivity
======MainActivity.java===================================== package com.zys.myexpandablelistactivit ...
- ExpandableListActivity
main.xml: <?xml version="1.0" encoding="UTF-8"?> <LinearLayout xmlns:an ...
- 仿qq联系人 学习笔记---ExpandableListActivity的使用
[转]原地址 http://blog.163.com/xygzx@126/blog/static/237809502011102010100331/ 效果显示图: 1.布局文件 main.xml(E ...
- 《利用python进行数据分析》读书笔记--第六章 数据加载、存储与文件格式
http://www.cnblogs.com/batteryhp/p/5021858.html 输入输出一般分为下面几类:读取文本文件和其他更高效的磁盘存储格式,加载数据库中的数据.利用Web API ...
- 利用 Django REST framework 编写 RESTful API
利用 Django REST framework 编写 RESTful API Updateat 2015/12/3: 增加 filter 最近在玩 Django,不得不说 rest_framewor ...
- 实现UITableView循环利用
tableViewUITableView循环利用 前言 大家都知道UITableView,最经典在于循环利用,这里我自己模仿UITableView循环利用,写了一套自己的TableView实现方案,希 ...
随机推荐
- Altium Designer之AD16在Win10系统下无法切换走线/布线模式的解决办法
有些童鞋会在Win10下使用AD16的时候发现,走线模式/布线模式(切换直角,45°,弧形等)不能切换. 问题出在输入法上,一般是切换到英文输入法即可解决,但是有一种情况是win10系统自带输入法有时 ...
- ENode框架Conference案例分析系列之 - Quick Start
前言 前一篇文章介绍了Conference案例的架构设计,本篇文章开始介绍Conference案例的代码实现.由于代码比较多,一开始就全部介绍所有细节,估计很多人接受不了,也理解不了.所以,我先进行一 ...
- Cisco VPN can't work in Win8
Goto HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\CvirtA Change DisplayName to "Cisco ...
- 代码提交的时候可以插入表情了-GitHub表情的使用
GitHub官方有个表情项目,旨在丰富文字信息.意味着你可以在提交代码的时候,在提交信息里面添加表情,同时也可以在项目的ReadMe.md文件里面使用表情.除此之外,当然还有项目在GitHub上的wi ...
- 【玩转单片机系列001】 08接口双色LED显示屏驱动方式探索
前些日子,从淘宝上购得一块08接口的双色LED显示屏(打算做个音乐频谱显示器),捣鼓了好几天,终于搞清楚了其控制原理,在这里做个总结,算是备忘吧. 1.LED显示屏的扫描方式 LED显示屏的扫描方式有 ...
- Node.js开发者最常范的10个错误
目录 前言 1 不使用开发工具 1.1 自动重启工具 1.2 浏览器自动刷新工具 2 阻塞event loop 3 频繁调用回调函数 4 圣诞树结构的回调(回调的地狱) 5 创建一个大而完整的应用程序 ...
- 《Entity Framework 6 Recipes》中文翻译系列 (15) -----第三章 查询之与列表值比较和过滤关联实体
翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 3-8与列表值比较 问题 你想查询一个实体,条件是给定的列表中包含指定属性的值. 解 ...
- Linux study
在centos5.5中编译LNMP环境 一.配置好ip, dns, 网关, 确保使用远程连接工具能够连接服务器 centos设置ip地址,网关, dns教程: http://www.osyumwei. ...
- Drupal8重命名上传的中文名文件
完整的模块代码文件在Coding.net上,想直接使用的请前往下载:https://coding.net/u/yamus/p/chinese_rename/git/tree/master 最近吧Dru ...
- SQL Server 数据库子查询基本语法
一.SQL子查询语句 1.单行子查询 select ename,deptno,sal from emp where deptno=(select deptno ...