利用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并发编程(十七)Executor框架和线程池
转载请注明出处:http://blog.csdn.net/ns_code/article/details/17465497 Executor框架简介 在Java 5之后,并发编程引入了一堆新的启动 ...
- js判断地址转向
<script type="text/javascript"> if (navigator.userAgent.search(/iphone|ipod|ipad|And ...
- ASP.NET Identity V2
Microsoft.AspNet.Identity是微软在MVC 5.0中新引入的一种membership框架,和之前ASP.NET传统的membership以及WebPage所带来的SimpleMe ...
- UITableView(一)
#import <UIKit/UIKit.h> @interface ViewController : UIViewController<UITableViewDataSource, ...
- SQL Server 复制订阅
标签:SQL SERVER/MSSQL SERVER/数据库/DBA/高性能解决方案/高可用 概述 配置复制就没有数据库镜像和AlwaysOn的要求那么高,只需要两台服务器能通过TCP进行通讯即可,两 ...
- Please Call Me NIO
与其他语言相比,Java的IO功能显得异常复杂,各种流操作,通过程序员多次封装才可以达到操作文件的目的.自从jdk1.4之后,java提供了一个新的api完成IO操作,人称New IO(NIO),使用 ...
- 用.NET MVC实现长轮询,与jQuery.AJAX即时双向通信
两周前用长轮询做了一个Chat,并移植到了Azure,还写了篇博客http://www.cnblogs.com/indream/p/3187540.html,让大家帮忙测试. 首先感谢300位注册用户 ...
- 今天Windows Azure Live to Code的分享
今天参加了微软广州的Live to Code,晚上回公司OT写了封报告E-mail,也没让公司今天白出工资给我... 因为没有涉及到公司机密什么的,所以就拿出来跟大家分享一下. 首先要说明的是,在会议 ...
- 了解Package Configurations
使用VS2010创建的SSIS Project有两种deployment model:project deployment 和 package deployment,默认是Project deploy ...
- SQL Server中使用Check约束提升性能
在SQL Server中,SQL语句的执行是依赖查询优化器生成的执行计划,而执行计划的好坏直接关乎执行性能. 在查询优化器生成执行计划过程中,需要参考元数据来尽可能生成高效的执行计划, ...