利用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实现方案,希 ...
随机推荐
- Java json串生成及转bean
package com; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import j ...
- Altium Designer之AD16在Win10系统下无法切换走线/布线模式的解决办法
有些童鞋会在Win10下使用AD16的时候发现,走线模式/布线模式(切换直角,45°,弧形等)不能切换. 问题出在输入法上,一般是切换到英文输入法即可解决,但是有一种情况是win10系统自带输入法有时 ...
- java 过滤器Filter
一.首先在web.xml里进行拦截过滤 <filter> <filter-name>platformServiceAgreementFilter</filt ...
- laravel5.2,注册服务提供者时无法生效
laravel中注册服务提供者原本很简单,只要运行下指令php artisan make:provider TestServiceProvider,然后在config/app.php的provider ...
- Lua源代码阅读分析问题列表(转)
最近正在阅读lua源码,遇到座灯塔,转载如下: 我个人的习惯是带着问题去研究一个新题目,比如这次阅读Lua代码,暂列下面这些问题. 1)什么是基于栈.基于寄存器的虚拟机(VM)设计?Lua如何实现基于 ...
- VS加入全局缓存
1. 加载 gacutil.exe /i <DLL Name>.dll 2. 卸载 gacutil.exe /u <DLL Name>
- gulp es7配置文件
http://sanwen.net/a/ybsfcoo.html /** * Created by udi on 2016/11/24. */ var gulp = require('gulp'); ...
- Lesson 10 Not for jazz
Text We have an old musical instrument. It is called a clavichord. It was made in Germany in 1681. O ...
- Nova PhoneGap框架 第四章 本地数据库
我一直想把EntityFramework(简称EF)的那一套搬过来,应用于HTML5 SQLite. 幸运的是,我几乎做到了,有些功能无法完成的那是因为SQLite本身不支持.至少从现在已经完成的功能 ...
- ES7之Decorators实现AOP示例
在上篇博文CoffeeScript实现Python装潢器中,笔者利用CoffeeScript支持的高阶函数,以及方法调用可省略括符的特性,实现了一个类似Python装潢器的日志Demo.这只是一种伪实 ...