MainActivity.java

package com.example.mars_2300_expandablelist;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleExpandableListAdapter;
import android.os.Build; public class MainActivity extends ExpandableListActivity {
/** Called when the activity is first created. */
@Override
public 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);
}
}

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/android:empty"
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>

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

android之ExpandableListActivity的更多相关文章

  1. Android :ExpandableListActivity

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

  2. android ExpandableListActivity的使用

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

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

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

  4. Android ExpandableListActivity

    ======MainActivity.java===================================== package com.zys.myexpandablelistactivit ...

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

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

  6. Android Listview

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

  7. android 之 ExpandableListView列表中的列表

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

  8. android学习笔记26——Activity

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

  9. Android开发学习之LauncherActivity开发启动的列表

    Android开发学习之LauncherActivity开发启动的列表 创建项目:OtherActivity 项目运行结果:   建立主Activity:OtherActivity.java [jav ...

随机推荐

  1. Intel指令集专有词解释

    SSE 概述 SSE(Streaming SIMD Extensions)是英特尔在AMD的3D Now!发布一年之后,在其计算机芯片Pentium III中引入的指令集,是MMX的超集.AMD后来在 ...

  2. 使用架构(XSD)验证XML文件

    假使说XML是一个数据库,那么XSD就是这个数据库的结构.由此可见,XSD是如此重要,如果没有它,我们如何声明以及验证我们需要的XML数据文件的格式和合法性呢?那是不可能完成的任务,如果你将XML数据 ...

  3. Java 多线程程序设计

    课程  Java面向对象程序设计 一.实验目的 掌握多线程程序设计 二.实验环境 1.微型计算机一台 2.WINDOWS操作系统,Java SDK,Eclipse开发环境 三.实验内容 1.Java有 ...

  4. OpenJudge计算概论-称体重【枚举法、信息数字化】

    /*====================================================================== 称体重 总时间限制: 1000ms 内存限制: 655 ...

  5. PHP 5.6.11 访问SQL Server2008R2

    PHP天生支持MySQL,但是有时候也想让它访问SQL Server,该怎么办呢? 最近找了点资料,测试成功了PHP访问SQLSvr的几种情况,限于时间,还没有测试更多不同环境,把测试过的记录如下: ...

  6. java指针

    import java.util.ArrayList; import java.util.List; public class TestPoint { public static void main( ...

  7. HttpClient简介 post get -转自ibm

    HttpClient简介 HTTP 协议可能是现在 Internet 上使用得最多.最重要的协议了,越来越多的 Java 应用程序需要直接通过 HTTP 协议来访问网络资源.虽然在 JDK 的 jav ...

  8. linux vi 工具的使用

    linux vi 工具的使用 1.打开文件 vi filename 如果存在该文件,则打开,不存在,则删除 2. 进入vi后,按i建,可以输入内容, 按ESC 在按: ,输入wq保存并退出. 3.移动 ...

  9. 如何通过源码生成Gatling可执行工具

    其实,这个对于不是很熟系sbt的人来说,或者对scala语言没有什么了解的人,接触Gatling这个开源的性能测试框架,还是有些茫然的. 因为GitHub上提供的Gatling (最新版本:2.2.0 ...

  10. This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms

    异常消息:This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms ...