ExpandableListActivity

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>
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"
> <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" />
</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>
MainActivity.java:
package mars.expandable; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.widget.SimpleExpandableListAdapter; /*
* 创建一个Activity,继承ExpandableListAcitivty
*/
public class MainActivity extends ExpandableListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.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);
}
}
效果如图:

ExpandableListActivity的更多相关文章
- 利用SimpleExpandableListAdapter为ExpandableListActivity提供数据
首先MainActivity继承自ExpandableListActivity,其中的声明如下: setContentView(R.layout.expandmain); //定义一个:List,该L ...
- 仿qq联系人 学习笔记---ExpandableListActivity的使用
[转]原地址 http://blog.163.com/xygzx@126/blog/static/237809502011102010100331/ 效果显示图: 1.布局文件 main.xml(E ...
- android之ExpandableListActivity
MainActivity.java package com.example.mars_2300_expandablelist; import java.util.ArrayList; import j ...
- android ExpandableListActivity的使用
package com.example.keKuoZhanLieBiao; import android.app.ExpandableListActivity; import android.os.B ...
- listActivity和ExpandableListActivity的简单用法
http://www.cnblogs.com/limingblogs/archive/2011/10/09/2204866.html 今天自己简单的总结了listActivity和Expandable ...
- Android ExpandableListActivity的简单介绍及小例子
Android中常常要用到ListView,但也经常要用到ExpandableListView,ListView是显示列表,而ExpandableListView显示的是分类的列表: 下面用一个例子来 ...
- Android :ExpandableListActivity
http://developer.android.com/reference/android/app/ExpandableListActivity.html# public class Expanda ...
- Android ExpandableListActivity
======MainActivity.java===================================== package com.zys.myexpandablelistactivit ...
- ExpandableListActivity的基本使用方法 ,SimpleExpandableListAdapter的基本使用方法
activity_main.xml: <ExpandableListView android:id="@id/android:list" android:layout_wid ...
随机推荐
- 根据权限显示accordion
前端界面: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Home.asp ...
- centos8下gz,bz2,zip压缩解压缩
for gz 1.制作压缩包 [root@192 mnt]# tar czf mydir.tar.gz mydir1/ 2.解压gz 压缩包 [root@192 mnt]# tar xvf mydir ...
- STM32F103_外部RAM用作运存
概述 SRAM的简介 折腾过电脑的朋友都知道,当电脑运行比较卡的时候,我们可以通过给电脑加装内存条来改善电脑的性能.那么号称微型计算机的单片机能不能像电脑一样加装内存条呢?装内存条倒是不行,但是我们可 ...
- APDL获取节点和单元的结果
目录 1. 获取节点结果 1.1 获取节点应力结果 1.2 获取节点位移结果 1.3 获取节点应变结果--总应变 1.4 获取节点应变结果--弹性应变 1.5 获取节点应变结果--塑性应变 1.6 获 ...
- Laravel 6.X 数据库迁移 创建表 与 修改表
数据库迁移创建表 本篇文章中使用的是mysql数据库,其他数据库需要修改env文件和app配置,请其他地方搜索一下就会找到. 创建示例 1.创建users表: 命令行键入 php artisan ma ...
- MySQL - 设置UTF-8编码
1. 在Windows上,安装时请选择UTF-8编码,以便正确地处理中文. 在Mac或Linux上,需要编辑MySQL的配置文件,把数据库默认的编码全部改为UTF-8.MySQL的配置文件默认存放在/ ...
- K8S-OVS使用Openvswitch为提供SDN功能支持单租户模式和多租户模式
k8s-ovs ============================== 最近在寻求一些工作机会,如果有kubernetes相关研发招聘的朋友,欢迎随时联系我.我的个人简历可以通过百度网盘:htt ...
- golang 中的引号
前言 go中的单引号',双引号",反引号`,他们用法的区别. 需要先了解字符编码的区别,由来. 单引号 单引号里面只能有一个字符,一般只能用来包裹一个字节的ASCII码字符.他的类型是Gol ...
- Linux系统在IT行业处于什么位置
相信每一位程序员对于linux都不陌生,不管是新入行的小白,还是有着十几年编程经验的大佬,都知道Linux在IT行业中的位置吧! 我是一名Web JAVA开发的小白,对于初入IT行业的小白来说,工 ...
- jsp页面 将数据以Json 格式保存到数据库
1:jsp页面 <div class="control-group form-group all_activity"> <c:choose> <c:w ...