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 组件来显示专家分类,每个分类点击之后可以显示专家的头像和名字. 很简单 ...
随机推荐
- 用于主题检测的临时日志(fe4edac1-b4f4-4673-ae87-110cbb7dbb5a - 3bfe001a-32de-4114-a6b4-4005b770f6d7)
这是一个未删除的临时日志.请手动删除它.(25ea5485-9168-424b-a30c-09cc1371e2d9 - 3bfe001a-32de-4114-a6b4-4005b770f6d7)
- C#学习笔记9:C#中的变量、转义符、显式转换和隐式转换
1.变量的特性:可以重复的赋值 int a=4; a=9; 2.常量:const int number=10:这个常量不可变 如果你声明的变量,不想被其他人修改,那么就修饰为常量 声明在类的下面, ...
- Android沉浸式状态栏实现
Step1:状态栏与导航栏半透明化 方法一:继承主题特定主题 在Android API 19以上可以使用****.TranslucentDecor***有关的主题,自带相应半透明效果 例如: < ...
- win2008远程桌面卡顿和上传慢的解决方法
ibm服务器安装win2008server系统,发现远程桌面登陆特别卡,上传也慢的要死.下载没问题,这样初步判断网络没有问题. 打开注册表(regedit)找到: (1)打开HKEY_LOCAL_MA ...
- Microsoft SQL Server Product Samples:Database
从SQL Server 2005 之后示例数据都为AdventureWorks,需要的通过codeplex网站下载.这样设计的目的应该在于是生产库行不必要的用户以及权限分配. 从以下网址访问http: ...
- [转]Windows Shell 编程 第三章 【转自:http://blog.csdn.net/wangqiulin123456/article/details/7987901】
第三章 操作文件 我依然清楚地记得,Windows95 的贝塔版出现的情形,它在朋友之间和学院中传播,好酷,全新的文件管理器,一种全图标,全彩色可客户化的界面,以及活泼的动画标识使得在文件拷贝和删除方 ...
- [转]Windows Shell 编程 第二章 【来源:http://blog.csdn.net/wangqiulin123456/article/details/7987893】
第二章Shell的结构 “Shell 编程”的大伞之下有大量的API函数和COM接口.这个种类繁多的‘命令’集允许你用不同的方法对Windows Shell进行编程.函数和接口并不是两种提供相同功能 ...
- 学习之spring注解DI疑惑
接口定义 package com; public interface IPaly { void say(); } 接口实现类 package com; import org.springframewo ...
- [leetcode] 401. Binary Watch
https://leetcode.com/contest/5/problems/binary-watch/ 这个题应该是这次最水的,这个题目就是二进制,然后是10位,最大1024,然后遍历,找二进制里 ...
- 信息收集->DNS分析->dnsdict6
如何获取域名的IPV4/IPV6地址之dnsdict6的使用 dnsdict6是一个用于获取网站信息的工具.dnsdict6可以扫描网站并显示有多少域或者子域,也可以扫描ipv6/ipv4地址.dns ...