首先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提供数据的更多相关文章

  1. 如何做好 Android 端音视频测试?

    在用户眼中,优秀的音视频产品应该具有清晰.低延时.流畅.秒开.抗丢包.高音效等特征.为了满足用户以上要求,网易云信的工程师通过自建源站,在SDK端为了适应网络优化进行QoS优化,对视频编码器进行优化, ...

  2. ExpandableListActivity的基本使用方法 ,SimpleExpandableListAdapter的基本使用方法

    activity_main.xml: <ExpandableListView android:id="@id/android:list" android:layout_wid ...

  3. android之ExpandableListActivity

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

  4. Android ExpandableListActivity

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

  5. ExpandableListActivity

    main.xml: <?xml version="1.0" encoding="UTF-8"?> <LinearLayout xmlns:an ...

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

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

  7. 《利用python进行数据分析》读书笔记--第六章 数据加载、存储与文件格式

    http://www.cnblogs.com/batteryhp/p/5021858.html 输入输出一般分为下面几类:读取文本文件和其他更高效的磁盘存储格式,加载数据库中的数据.利用Web API ...

  8. 利用 Django REST framework 编写 RESTful API

    利用 Django REST framework 编写 RESTful API Updateat 2015/12/3: 增加 filter 最近在玩 Django,不得不说 rest_framewor ...

  9. 实现UITableView循环利用

    tableViewUITableView循环利用 前言 大家都知道UITableView,最经典在于循环利用,这里我自己模仿UITableView循环利用,写了一套自己的TableView实现方案,希 ...

随机推荐

  1. 安装使用Oracle OSWbb/OSWbba工具

    OSWbb是收集数据,OSWbba 是分析数据,在OSWbb4.0以后,OSWbba已经绑定在OSWbb内. 1.创建目录,上传/解压安装包 [oracle@std ~]$ mkdir oswbb [ ...

  2. Unity3D UGUI之ScrollView弹簧效果

    unity3d版本5.3.2p4 UGUI中ScrollView包含Viewport(Content) ScrollView包含脚本.其Movement Type一共3个选项.Elastic就是弹簧效 ...

  3. H5 表单

    伴随着互联网富应用以及移动开发的兴起,传统的Web表单已经越来越不能满足开发的需求,HTML5在Web表单方向也做了很大的改进,如拾色器.日期/时间组件等,使表单处理更加高效. 1.1新增表单类型 - ...

  4. HDFS NameNode 设计实现解析

    接前文 分布式存储-HDFS 架构解析,我们总体分析了 HDFS 架构的主要构成组件包括:NameNode.DataNode 和 Client.本文首先进一步解析 HDFS NameNode 的设计和 ...

  5. 使用 OWIN Self-Host ASP.NET Web API 2

    Open Web Interface for .NET (OWIN)在Web服务器和Web应用程序之间建立一个抽象层.OWIN将网页应用程序从网页服务器分离出来,然后将应用程序托管于OWIN的程序而离 ...

  6. 一个基于Orchard的开源CRM --coevery简介

    Coevery是开源的.NET Web平台项目,力争打造一个开放而鲁棒的CRM系统,采用Orchard架构,并使用AngularJS改善页面体验.作为一个后发优势的CRM 产品,Coevery 具有一 ...

  7. Setting Up KeePass For Centos 6

    This mini-howto describes how to set up KeePass on Centos 6. It requires building mono from source a ...

  8. ABP理论学习之验证DTO

    返回总目录 本篇目录 验证介绍 使用数据注解 自定义验证 标准化 验证介绍 首先应该验证应用的输入.用户或者其它应用都可以向该应用发送输入.在一个web应用中,验证通常要实现两次:在客户端和服务器端. ...

  9. 測試大型資料表的 Horizontal Partitioning 水平切割

    FileGroup 檔案群組 :一個「資料庫(database)」可對應一或多個 FileGroup,一個 FileGroup 可由一或多個 file (.ndf) 構成. FileGroup 可讓 ...

  10. JS实战 · 实践积累点滴杂烩

    onmouseover : 鼠标进入 onmouseout : 鼠标离开 onfocus:得到焦点   表单提交执行JS代码,有两种常用方式. 一:在局部(比如按钮定义处)用onclick=" ...