Expandablelistview1Activity.java

package com.wangzhu.demoexpandablelistview;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import android.app.Activity;
import android.os.Bundle;
import android.widget.ExpandableListView;
import android.widget.SimpleExpandableListAdapter; public class Expandablelistview1Activity extends Activity { private ExpandableListView expandableListView1; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.expandablelistview1); init();
} private void init() {
expandableListView1 = (ExpandableListView) findViewById(R.id.expandableListView1);
getDatas();
} private void getDatas() {
// 创建两个一级条目标题
Map<String, String> title_1 = new HashMap<String, String>();
title_1.put("group", "移动开发");
Map<String, String> title_2 = new HashMap<String, String>();
title_2.put("group", "男人的需求"); // 创建一级条目容器
List<Map<String, String>> groups = new ArrayList<Map<String, String>>();
groups.add(title_1);
groups.add(title_2); // 创建二级条目内容 // 内容一
Map<String, String> content_1 = new HashMap<String, String>();
content_1.put("child", "Android");
Map<String, String> content_2 = new HashMap<String, String>();
content_2.put("child", "Ios"); List<Map<String, String>> childs_1 = new ArrayList<Map<String, String>>();
childs_1.add(content_1);
childs_1.add(content_2); // 内容二
Map<String, String> content_3 = new HashMap<String, String>();
content_3.put("child", "金钱");
Map<String, String> content_4 = new HashMap<String, String>();
content_4.put("child", "权利");
Map<String, String> content_5 = new HashMap<String, String>();
content_5.put("child", "女人"); List<Map<String, String>> childs_2 = new ArrayList<Map<String, String>>();
childs_2.add(content_3);
childs_2.add(content_4);
childs_2.add(content_5); // 存放两个内容,以便显示在列表中
List<List<Map<String, String>>> childs = new ArrayList<List<Map<String, String>>>();
childs.add(childs_1);
childs.add(childs_2); /**
* 参数1:上下文对象context 参数2:一级条目目录集合 参数3:一级条目对应的布局文件
* 参数4:fromto,就是map中的key,指定要显示的对象 参数5:与参数4对应,指定要显示在groups中的id
* 参数6:二级条目目录集合 参数7:二级条目对应的布局文件 参数8:fromto,就是map中的key,指定要显示的对象
* 参数9:与参数8对应,指定要显示在childs中的id
*/
SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter(
this, groups, R.layout.expandablelistview1_groups,
new String[] { "group" }, new int[] { R.id.textGroup }, childs,
R.layout.expandablelistview1_child, new String[] { "child" },
new int[] { R.id.textChild });
expandableListView1.setAdapter(adapter);
} }

expandablelistview1.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/expandableListView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ExpandableListView> </LinearLayout>

expandablelistview1_groups.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/textGroup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="6dp"
android:paddingLeft="40dp"
android:paddingTop="6dp"
android:text="No data"
android:textSize="15sp" /> </LinearLayout>

expandablelistview1_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/textChild"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dp"
android:paddingLeft="40dp"
android:paddingTop="10dp"
android:text="No data"
android:textSize="20sp" /> </LinearLayout>

备注:

简单的应用,网上导出都可见,理论就不写了,直接源码吧!

Android ExpandableListView的简单应用的更多相关文章

  1. 【开源项目4】Android ExpandableListView

    如果你对Android提供的Android ExpandableListView并不满意,一心想要实现诸如Spotify应用那般的效果,那么SlideExpandableListView绝对是你最好的 ...

  2. Android:PopupWindow简单弹窗改进版

    Android:PopupWindow简单弹窗 继续上一节的内容,改进一下,目标是点击菜单后把菜单收缩回去并且切换内容,我使用的是PopupWindow+RadioGroup public class ...

  3. Android.mk文件简单分析

    Android.mk文件简单分析 一个Android.mk文件用来向编译系统描写叙述须要编译的源码.详细来说:该文件是GNUMakefile的一小部分.会被编译系统解析一次或多次. 能够在每个Andr ...

  4. IDA 调试 Android 方法及简单的脱壳实现

    IDA 调试 Android 方法及简单的脱壳实现 标签: android原创逆向调试dalvik 2016-05-24 14:24 9286人阅读 评论(3) 收藏 举报 分类: 原创(25) An ...

  5. android EventBus的简单使用

    今天,简单讲讲Android里关于EventBus的使用. 这几天,由于面试的缘故,我听到了很多Android的流行框架,但是之前自己在公司做APP时并没有使用,所以没有了解.于是在网上查找了资料,学 ...

  6. Android 百度地图 简单实现--- 美食搜索

    Android 百度地图 简单实现---  美食 依赖包: 加入 Android 百度依赖包: 1  key:  <!--        开发人员 key --> <meta-dat ...

  7. [Android]RecyclerView的简单演示样例

    去年google的IO上就展示了一个新的ListView.它就是RecyclerView. 下面是官方的说明,我英语能力有限,只是我大概这么理解:RecyclerView会比ListView更具有拓展 ...

  8. Android ExpandableListView 带有Checkbox的简单应用

    expandablelistview2_groups.xml <?xml version="1.0" encoding="utf-8"?> < ...

  9. 解决android expandablelistview 里面嵌入gridview行数据重复问题

    最近做了一个“csdn专家博客App” 当然了是android版本,在专家浏览页面,我才用了expandablelistview 组件来显示专家分类,每个分类点击之后可以显示专家的头像和名字. 很简单 ...

随机推荐

  1. 百度贴吧图片抓取工具(Python)

    废话不多说,直接上源码. import os,urllib,urllib2,re path='E:/img' #图片保存路径 url=raw_input('Please input URL:')#贴吧 ...

  2. DOS批处理命令-@命令

    @命令是一个禁止当前语句回显的简单命令. 语法: @[command].[command]是要屏蔽的批处理命令 例如执行包含以下内容的bat文件 echo on @echo ------- @echo ...

  3. powerdesign设置实体显示格式

    工具-显示参数选择中,如下图:

  4. excel知识

    excel中导出文本中的制表符去除方法:

  5. SQLserver中的常量与变量、判断循环语句

    数据库中的变量与常量 数据库中定义变量 [起临时存储数据的作用] ---数据库中定义变量(运行时要从头到尾进行运行,从定义变量开始到赋值) --前面必须加 declare --定义变量 :    de ...

  6. 通过自关联替代开窗函数实现SQL优化

    数据库环境:SQL SERVER 2005 我们平时都是通过开窗析函数来取代自关联,减少表扫描,从而优化SQL.今天,反其道而行, 用自关联改写开窗函数.我们先来看一下SQL. 原SQL语句 SELE ...

  7. 【html】【12】特效篇--轮播图

    必看参考: http://www.runoob.com/bootstrap/bootstrap-carousel-plugin.html 代码: <!DOCTYPE html> <h ...

  8. 轮子来袭 vJine.Core Orm 之 02_代码生成

    1.下载并安装动软代码生成器: 2.下载vJine.Core.Orm模板: 3.解压模本文件并复制到如下的动软代码生成器模板目录: 4.打开动软代码生成器会看到模板已识别加载: 5.选择模板代码批量生 ...

  9. vmware workstation下的虚拟Linux通过NAT模式共享上网

    在vmware workstation虚拟机下面,Linux虚机要上网,一般是桥接模式,但我自己的电脑上网的环境不同,也懒得去总是配置Linux的网卡信息,所以,设置为NAT模式来共享真机的上网网卡来 ...

  10. evaluateScript--evaluatePopoverScript--区别

    appcan.window.evaluateScript({})              //window.open()页面之间使用 appcan.window.evaluatePopoverScr ...