ExpandableListActivity

main.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
> <ExpandableListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"/> <TextView android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No data"/>
</LinearLayout>
group.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
> <TextView android:id="@+id/groupTo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="60px"
android:paddingTop="10px"
android:paddingBottom="10px"
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:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"> <TextView android:id="@+id/childTo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="50px"
android:paddingTop="5px"
android:paddingBottom="5px"
android:textSize="20sp"
android:text="No data" />
</LinearLayout>
MainActivity.java:
package mars.expandable; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.widget.SimpleExpandableListAdapter; /*
* 创建一个Activity,继承ExpandableListAcitivty
*/
public class MainActivity extends ExpandableListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//定义一个List,该List对象为一级条目提供数据
List<Map<String, String>> groups = new ArrayList<Map<String, String>>();
Map<String, String> group1 = new HashMap<String, String>();
group1.put("group", "group1");
Map<String, String> group2 = new HashMap<String, String>();
group2.put("group", "group2");
groups.add(group1);
groups.add(group2); //定义一个List,该List对象为第一个一级条目提供二级条目的数据
List<Map<String, String>> child1 = new ArrayList<Map<String, String>>();
Map<String, String> child1Data1 = new HashMap<String, String>();
child1Data1.put("child", "child1Data1");
child1.add(child1Data1);
Map<String,String> child1Data2 = new HashMap<String,String>();
child1Data2.put("child", "child1Data2");
child1.add(child1Data2); //定义一个List,该List对象为第二个一级条目提供二级条目的数据
List<Map<String, String>> child2 = new ArrayList<Map<String, String>>();
Map<String, String> child2Data = new HashMap<String, String>();
child2Data.put("child", "child2Data");
child2.add(child2Data); //定义一个List,该List对象用来存储所有的二级条目的数据
List<List<Map<String, String>>> childs = new ArrayList<List<Map<String, String>>>();
childs.add(child1);
childs.add(child2); //生成一个SimpleExpandableListAdapter对象
//1.context
//2.一级条目的数据
//3.用来设置一级条目样式的布局文件
//4.指定一级条目数据的key
//5.指定一级条目数据显示控件的id
//6.指定二级条目的数据
//7.用来设置二级条目样式的布局文件
//8.指定二级条目数据的key
//9.指定二级条目数据显示控件的id
SimpleExpandableListAdapter sela = new SimpleExpandableListAdapter(
this, groups, R.layout.group, new String[] { "group" },
new int[] { R.id.groupTo }, childs, R.layout.child,
new String[] { "child" }, new int[] { R.id.childTo });
//将SimpleExpandableListAdapter对象设置给当前的ExpandableListActivity
setListAdapter(sela);
}
}
效果如图:

ExpandableListActivity的更多相关文章
- 利用SimpleExpandableListAdapter为ExpandableListActivity提供数据
首先MainActivity继承自ExpandableListActivity,其中的声明如下: setContentView(R.layout.expandmain); //定义一个:List,该L ...
- 仿qq联系人 学习笔记---ExpandableListActivity的使用
[转]原地址 http://blog.163.com/xygzx@126/blog/static/237809502011102010100331/ 效果显示图: 1.布局文件 main.xml(E ...
- android之ExpandableListActivity
MainActivity.java package com.example.mars_2300_expandablelist; import java.util.ArrayList; import j ...
- android ExpandableListActivity的使用
package com.example.keKuoZhanLieBiao; import android.app.ExpandableListActivity; import android.os.B ...
- listActivity和ExpandableListActivity的简单用法
http://www.cnblogs.com/limingblogs/archive/2011/10/09/2204866.html 今天自己简单的总结了listActivity和Expandable ...
- Android ExpandableListActivity的简单介绍及小例子
Android中常常要用到ListView,但也经常要用到ExpandableListView,ListView是显示列表,而ExpandableListView显示的是分类的列表: 下面用一个例子来 ...
- Android :ExpandableListActivity
http://developer.android.com/reference/android/app/ExpandableListActivity.html# public class Expanda ...
- Android ExpandableListActivity
======MainActivity.java===================================== package com.zys.myexpandablelistactivit ...
- ExpandableListActivity的基本使用方法 ,SimpleExpandableListAdapter的基本使用方法
activity_main.xml: <ExpandableListView android:id="@id/android:list" android:layout_wid ...
随机推荐
- .NET中的字符串(2):你真的了解.NET中的String吗?
概述 String在任何语言中,都有它的特殊性,在.NET中也是如此.它属于基本数据类型,也是基本数据类型中唯一的引用类型.字符串可以声明为常量,但是它却放在了堆中.希望通过本文能够使大家对.NET中 ...
- 最全的Java操作Redis的工具类,使用StringRedisTemplate实现,封装了对Redis五种基本类型的各种操作!
转载自:https://github.com/whvcse/RedisUtil 代码 ProtoStuffSerializerUtil.java import java.io.ByteArrayInp ...
- Bugku - CTF加密篇之滴答~滴
滴答~滴 答案格式KEY{xxxxxxxxx}
- oracle用户密码忘记怎么修改
安装完数据库很久不用常常会忘记其密码,碰到这种情况不要动不动就重装数据库,按其下方法修改即可. 一:忘记sys,system用户的密码 1,在开始菜单点击‘运行’,输入‘cmd’,打开命令提示窗口,输 ...
- 获取class对象的三种方法以及通过Class对象获取某个类中变量,方法,访问成员
public class ReflexAndClass { public static void main(String[] args) throws Exception { /** * 获取Clas ...
- Ext插件中控件的xtype和类的对应关系总结
xtype Class ------------- ------------------ box Ext.BoxComponent button Ext.Button buttongroup Ext. ...
- Educational Codeforces Round 81 (Rated for Div. 2)
A 0~9需要多少笔画,自取7和1,判奇偶 #include<bits/stdc++.h> using namespace std; #define ll long long #defin ...
- 后端——框架——持久层框架——Mybatis——补充——pageHelper(分页)插件
Pagehelper插件的知识点大致可以分为三个部分 搭建环境,引入jar包,配置. 使用方式,只需要记住一种即可.类似于在写SQL语句中,可以left join,也可以right join,它们实现 ...
- FastDFS文件上传和下载流程
文件上传流程 客户端上传文件后存储服务器将文件 ID 返回给客户端,此文件 ID 用于以后访问该文件的索引信息.文件索引信息包括:组名,虚拟磁盘路径,数据两级目录,文件名. 组名:文件上传后所在的 ...
- cmake学习资料收集
CMake 学习笔记 : https://www.jianshu.com/p/c417e4ab8b30