Android ExpandableListView的简单应用
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的简单应用的更多相关文章
- 【开源项目4】Android ExpandableListView
如果你对Android提供的Android ExpandableListView并不满意,一心想要实现诸如Spotify应用那般的效果,那么SlideExpandableListView绝对是你最好的 ...
- Android:PopupWindow简单弹窗改进版
Android:PopupWindow简单弹窗 继续上一节的内容,改进一下,目标是点击菜单后把菜单收缩回去并且切换内容,我使用的是PopupWindow+RadioGroup public class ...
- Android.mk文件简单分析
Android.mk文件简单分析 一个Android.mk文件用来向编译系统描写叙述须要编译的源码.详细来说:该文件是GNUMakefile的一小部分.会被编译系统解析一次或多次. 能够在每个Andr ...
- IDA 调试 Android 方法及简单的脱壳实现
IDA 调试 Android 方法及简单的脱壳实现 标签: android原创逆向调试dalvik 2016-05-24 14:24 9286人阅读 评论(3) 收藏 举报 分类: 原创(25) An ...
- android EventBus的简单使用
今天,简单讲讲Android里关于EventBus的使用. 这几天,由于面试的缘故,我听到了很多Android的流行框架,但是之前自己在公司做APP时并没有使用,所以没有了解.于是在网上查找了资料,学 ...
- Android 百度地图 简单实现--- 美食搜索
Android 百度地图 简单实现--- 美食 依赖包: 加入 Android 百度依赖包: 1 key: <!-- 开发人员 key --> <meta-dat ...
- [Android]RecyclerView的简单演示样例
去年google的IO上就展示了一个新的ListView.它就是RecyclerView. 下面是官方的说明,我英语能力有限,只是我大概这么理解:RecyclerView会比ListView更具有拓展 ...
- Android ExpandableListView 带有Checkbox的简单应用
expandablelistview2_groups.xml <?xml version="1.0" encoding="utf-8"?> < ...
- 解决android expandablelistview 里面嵌入gridview行数据重复问题
最近做了一个“csdn专家博客App” 当然了是android版本,在专家浏览页面,我才用了expandablelistview 组件来显示专家分类,每个分类点击之后可以显示专家的头像和名字. 很简单 ...
随机推荐
- Android Metro风格的Launcher开发系列第二篇
前言: 各位小伙伴们请原谅我隔了这么久才开始写这一系列的第二篇博客,没办法忙新产品发布,好了废话不说了,先回顾一下:在我的上一篇博客http://www.cnblogs.com/2010wuhao/p ...
- java多线程总结五:线程池的原理及实现
1.线程池简介: 多线程技术主要解决处理器单元内多个线程执行的问题,它可以显著减少处理器单元的闲置时间,增加处理器单元的吞吐能力. 假设一个服务器完成一项任务所需时间为:T1 创 ...
- lua package path 设置方法
lua package path 设置方法: 添加环境变量LUA_PATH="/add_path/?.lua;;" 1.add_path为新添加的目录: 2.一定要添加双引号: 3 ...
- 第零篇、HTML5简介
1.什么是HTML5? 背景:互联网的快速兴起 1>网页5.0版本 2>2014年才定制HTML5标准 3>移动先行 2.为什么要使用HTML5? 1>跨平台(可以运行所有的浏 ...
- (poj)1064 Cable master 二分+精度
题目链接:http://poj.org/problem?id=1064 Description Inhabitants of the Wonderland have decided to hold a ...
- 学习C++ Primer 的个人理解(九)
这一章介绍顺序容器,在之前的第三章中,了解到的vector就属于顺序容器的一种. 一个容器就是一些特定类型对象的集合. 除了vector,还有哪些顺序容器? vector: 大小可变,随机访问的速度很 ...
- OpenJudge 2803 碎纸机 / Poj 1416 Shredding Company
1.链接地址: http://poj.org/problem?id=1416 http://bailian.openjudge.cn/practice/2803 2.题目: 总时间限制: 1000ms ...
- Qt-获取主机网络信息之QNetworkInterface
QNetworkInterface类提供了一个主机IP地址和网络接口的列表. QNetworkInterface表示了当前程序正在运行时与主机绑定的一个网络接口.每个网络接口可能包含0个或者多个IP地 ...
- Entity Framework 插入数据 解决主键非自增问题
http://blog.csdn.net/educast/article/details/8632806 与Entity Framework相伴的日子痛并快乐着.今天和大家分享一下一个快乐,两个痛苦. ...
- NOSQL之【WIN7的安装配置】
1.下载安装 大家根据各自系统配置,下载相对应的redis版本.我下载是redis 2.6 将redis.conf 复制到 bin/release/redisbin 里面 redis-server.e ...