activity_main.xml:

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

group.xml:

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

child.xml:

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

MainActivity.java:

package leihu.expandablelistview;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import android.os.Bundle;

import android.app.ExpandableListActivity;

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");

       Map<String,String> child1Data2 = new HashMap<String,String>();

       child1Data2.put("child", "child1Data2");

       child1.add(child1Data1);

       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的基本使用方法的更多相关文章

  1. 原生JS事件绑定方法以及jQuery绑定事件方法bind、live、on、delegate的区别

    一.原生JS事件绑定方法: 1.通过HTML属性进行事件处理函数的绑定如: <a href="#" onclick="f()"> 2.通过JavaS ...

  2. java 遍历map 方法 集合 五种的方法

    package com.jackey.topic; import java.util.ArrayList;import java.util.HashMap;import java.util.Itera ...

  3. 为什么Java方法里面不能再嵌套方法?

    直接原因: 这是Java基本语法定义的,方法中不可以再次声明方法,只能调用其他的方法. 个人理解: 1.方法栈是需要一个载体的,这个载体就是Class,如果一个方法的上一级不是一个类,就说明没有载体. ...

  4. iOS中的过期方法和新的替代方法

    关于iOS中的过期方法和新的替代方法 1.获取某些类的UINavigationBar的统一外观并设置UINavigationbar的背景 注:方法名改了但是基本使用方法不变 + (instancety ...

  5. java中的方法重载与重写以及方法修饰符

    1. 方法重载Overloading , 是在一个类中,有多个方法,这些方法的名字相同,但是具有不同的参数列表,和返回值 重载的时候,方法名要一样,但是参数类型和参数个数不一样,返回值类型可以相同,也 ...

  6. 使用jquery获取url及url参数的方法及定义JQuery扩展方法

    1.jquery获取url很简单,代码如下: window.location.href; 其实只是用到了javascript的基础的window对象,并没有用jquery的知识. 2.jquery获取 ...

  7. [Effective JavaScript 笔记]第20条:使用call方法自定义接收者来调用方法

    不好的实践 函数或方法的接收者(即绑定到特殊关键字this的值)是由调用者的语法决定的.方法调用语法将方法被查找的对象绑定到this变量,(可参阅之前文章<理解函数调用.方法调用及构造函数调用之 ...

  8. PHP其它常用函数;<<<面向对象(OPP)的三大特性:封装、继承、加态:>>> <----面试题 ;构造方法、析构方法,魔术方法、set、get方法;静态;抽象类;接口

    PHP其它常用函数:     赋值:$r->name = "元素";      取值: echo $r->name;  count()   计算数组中的元素数目或对象中 ...

  9. [原创]java WEB学习笔记79:Hibernate学习之路--- 四种对象的状态,session核心方法:save()方法,persist()方法,get() 和 load() 方法,update()方法,saveOrUpdate() 方法,merge() 方法,delete() 方法,evict(),hibernate 调用存储过程,hibernate 与 触发器协同工作

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  10. C# 中如何判断某个字符串是否为空的方法 分享了三个方法来判断字

    1. 三种常用的字符串判空串方法:Length法:bool isEmpty = (str.Length == 0);Empty法:bool isEmpty = (str == String.Empty ...

随机推荐

  1. spark实验(二)--eclipse安装scala环境(2)

    此次在eclipse中的安装参考这篇博客https://blog.csdn.net/lzxlfly/article/details/80728772 Help->Eclipse Marketpl ...

  2. Pycharm 分屏

    有图由真相 效果自在眼前

  3. Fizz Buzz in tensorflow

    code from keras.layers.normalization import BatchNormalization from keras.models import Sequential f ...

  4. python的空格和tab混用报错问题

    python中的空格和tab键不能混用,如果则会报类似如下的错误: IndentationError: unindent does not match any outer indentation le ...

  5. 【代码总结】PHP面向对象之抽象类

    一.什么是抽象方法? 一个方法如果没有方法体(不使用"{}",直接使用分号结束的方法,才是没有方法体的方法),则这个方法就是抽象方法 1.声明一个方法,不使用{},而直接分号结束 ...

  6. socket 多连接

    socket 多连接 本文档为文档https://www.cnblogs.com/wodeboke-y/p/11241472.html 后续内容. 上一文档中的案例2给出了一个阻塞型socket se ...

  7. 案例:WLC HA主WLC进入维护模式

    案例场景: 如图所示,7609-1和7609-2分别是网络中的核心设备,起了HSRP,7609-1连接的是WLC-1,,7609-2连接的是WLC-2,WLC1和WLC2的RP口相互连接. WLC的管 ...

  8. 思科室外AP无法注册到WLC

    思科的一些新的室外AP,在购买回来时,有时候会出现无法加入WLC的情况,现象基本是无法加入,或感觉加入了,立马又掉了. 例如: AIR-AP1562E-H-K9 AIR-AP1572EAC-H-K9 ...

  9. Python学习笔记010

    倒三角 num2 = int(input("Line:")) while num2 > 0:    num1 = num2    while num1 > 0:     ...

  10. vue修改当前页样式不影响公共样式的方法

    在项目开发中需要对一些标签进行样式修改但是每次修改之后其他页面的样式也会跟着改变, 在网上找了很多方法都不好使后来大神告诉我一种方法很好用分享给大家. 1:首先在template标签下的第一个div中 ...