首先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. EL表达式判断

    今天在做开发时遇到个小问题,就百度一番很快找到答案.这里记一下免得以后到处找... 在项目中显示项目名称时因为名字太长所以影响我的样式问题. 解决办法就是将固定长度之后的用"..." ...

  2. Ubuntu 安装Theano

    参考:http://deeplearning.net/software/theano/install_ubuntu.html 编译安装python3.4:http://blog.aboutc.net/ ...

  3. SQL Server2008附加数据库之后显示为只读时解决方法

    啰嗦的话就不多说了,直入主题吧! 方案一: 碰到这中情况一般是使用的sa账户登录的,只要改为Windows身份验证,再附加数据库即可搞定. 方案二: 使用sa登录SQL Server2008附加数据库 ...

  4. IOS第四天-新浪微博 -存储优化OAuth授权账号信息,下拉刷新,字典转模型

    *************application - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOpti ...

  5. 阿里巴巴分布式服务框架 Dubbo 团队成员梁飞专访

    项目主页:http://alibaba.github.io/dubbo-doc-static/Home-zh.htm 我的博客:http://javatar.iteye.com

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

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

  7. 简单明了区分escape、encodeURI和encodeURIComponent

    一.前言 讲这3个方法区别的文章太多了,但是大部分写的都很绕.本文试图从实践角度去讲这3个方法. 二.escape和它们不是同一类 简单来说,escape是对字符串(string)进行编码(而另外两种 ...

  8. HTML5特性速记图

    今天推荐大家一张HTML5特性速记图,供大家平时查阅,也可以打印放在电脑旁帮助速记.速查.此图笔者收集于网络图片.

  9. WPF PlacementTarget技巧

    <Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winf ...

  10. Tomcat搭建

    标签:Tomcat 概述 Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选. ...