======MainActivity.java=====================================

package com.zys.myexpandablelistactivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.os.Bundle;
import android.app.Activity;
import android.app.ExpandableListActivity;
import android.view.Menu;
import android.widget.SimpleExpandableListAdapter;

public class MainActivity extends ExpandableListActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_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);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}

========activity_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="match_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"
>

<ExpandableListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"/>

<TextView android:id="@+id/groupTo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
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>

Android ExpandableListActivity的更多相关文章

  1. android ExpandableListActivity的使用

    package com.example.keKuoZhanLieBiao; import android.app.ExpandableListActivity; import android.os.B ...

  2. Android ExpandableListActivity的简单介绍及小例子

    Android中常常要用到ListView,但也经常要用到ExpandableListView,ListView是显示列表,而ExpandableListView显示的是分类的列表: 下面用一个例子来 ...

  3. android之ExpandableListActivity

    MainActivity.java package com.example.mars_2300_expandablelist; import java.util.ArrayList; import j ...

  4. Android :ExpandableListActivity

    http://developer.android.com/reference/android/app/ExpandableListActivity.html# public class Expanda ...

  5. 利用SimpleExpandableListAdapter为ExpandableListActivity提供数据

    首先MainActivity继承自ExpandableListActivity,其中的声明如下: setContentView(R.layout.expandmain); //定义一个:List,该L ...

  6. 仿qq联系人 学习笔记---ExpandableListActivity的使用

    [转]原地址  http://blog.163.com/xygzx@126/blog/static/237809502011102010100331/ 效果显示图: 1.布局文件 main.xml(E ...

  7. Android Listview

    方法一: xml文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xml ...

  8. android 之 ExpandableListView列表中的列表

    有时候,我们需要设计这样一个界面,外面有一个列表,当我们点击其中列表中的某个条目时,就会展开这个条目,出现一个新的列表.比如下图:(程序运行的效果图,在这里贴出来) 当我们点击第一项时,视图变为: - ...

  9. android学习笔记26——Activity

    Activity ==> android中四大组件:Activity.Service.BroadcastReceiver.ContentProvider Activity组件用于对用户呈现操作界 ...

随机推荐

  1. TMS320C64x DSP L1 L2 Cache架构(1)——C64x Cache Architecture

    [前沿]研究生阶段从事于DSP和FPGA技术的相关研究工作,学习并整理了大量的技术资料,包括TI公司的官方文档和网络上的详细笔记,花费了大量的时间和精力总结了前人的工作成果.无奈工作却从事于嵌入式技术 ...

  2. 【POJ】1094 Sorting It All Out(拓扑排序)

    http://poj.org/problem?id=1094 原来拓扑序可以这样做,原来一直sb的用白书上说的dfs............ 拓扑序只要每次将入度为0的点加入栈,然后每次拓展维护入度即 ...

  3. ThinkPHP项目笔记之模板篇

    顾名思义:模板就是网页页面,有的是静态,有的的动态 基本语法: 1. <li><a href="{:U('User/searchlist')}">返回列表& ...

  4. 如何用ChemDraw中的ChemFinder查询反应过程

    ChemFinder是ChemDraw化学绘图软件的重要插件之一,ChemFinder是一个贮存众多化学信息的数据库管理系统,不仅可以用于查询基本化学结构,用户还可以用ChemFinder查询需要的反 ...

  5. 理解javascript函数调用和“this”

    http://blog.csdn.net/littlechang/article/details/8180550

  6. radio 标签状态改变时 触发事件

    <html> <head> <script src="jquery1.7.2.js"></script> </head> ...

  7. 在PHP项目中,每个类都要有对应的命名空间,为什么?

    语法: namespace  Admin\Controller; 功能: 命名空间主要用来区分控制器属于哪个模块下,好区分,更有利于项目的维护:

  8. 实际用户ID,有效用户ID,保存的设置用户ID

    Unix中常见的几个概念,下面做一个解释. 首先需要明确一点,这几个概念都是和进程相关的. real user ID表示的是实际上进程的执行者是谁,effective user ID主要用于校验该进程 ...

  9. Jquery之编辑不可修改

    <td class="queryTitle" width="100">优惠券批次号</td> <td class="qu ...

  10. JSP内置对象——request 及其响应get和post请求的实例

    request对象客户端的请求信息被封装在request对象中,通过它才能了解到客户的需求,然后做出响应.它是HttpServletRequest类的实例.request对象具有请求域,即完成客户端的 ...