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 组件来显示专家分类,每个分类点击之后可以显示专家的头像和名字. 很简单 ...
随机推荐
- RabbitMQ 原文译03--发布和订阅
发布/订阅 在之前的案例中我们创建了一个工作队列,这个工作队列的实现思想就是一个把每一个任务平均分配给每一个执行者,在这个篇文章我们会做一些不一样的东西,把一个消息发送给多个消费者,这种模式就被称作& ...
- SDK 组件 Qupaisdk 启动出错,错误消息为 [Qupaisdk], the android stack error message is Fail to start the plugin, which is caused by Failed resolution of: Lcom/duanqu/qupai/recorder/R$array;
紧急解决办法: 将你的oneSDK(qupaiSDK)里面的manifest的pageckage改为:com.duanqu.qupai.recorder
- Javascript中函数调用和this的关系
例子先行: var myObject={ foo:"bar", func:function(){ var self=this; console.log("outerfun ...
- phpize php扩展模块安装
安装(fastcgi模式)的时候,常常有这样一句命令:/usr/local/webserver/php/bin/phpize一.phpize是干嘛的?phpize是什么东西呢?php官方的说明:htt ...
- 接收Firfox RESTClient #Post请求
什么是 RESTClient 请参考:http://www.blogjava.net/paulwong/archive/2014/04/19/412688.html 对接接口时经常会需要传个异步回调消 ...
- Ext.Net学习笔记16:Ext.Net GridPanel 折叠/展开行
Ext.Net学习笔记16:Ext.Net GridPanel 折叠/展开行 Ext.Net GridPanel的行支持折叠/展开功能,这个功能个人觉得还说很有用处的,尤其是数据中包含图片等内容的时候 ...
- ###C中的extern-static-const关键词
#@date: 2014-06-14 #@author: gerui #@email: forgerui@gmail.com Contents extern的作用一般是用来声音一个外部变量和函数.一般 ...
- 轮子来袭 vJine.Core Orm 之 04_使用进阶
1.配置文件: 框架默认情况下支持"connectionStrings"的配置方式,如<轮子来袭 vJine.Core Orm 之 01_快速入门>所述: 框架的进阶设 ...
- From MSI to WiX, Part 2 - ARP support, by Alex Shevchuk
Following content is directly reprinted from From MSI to WiX, Part 2 - ARP support Author: Alex Shev ...
- OpenSessionInViewFilter与org.springframework.dao.InvalidDataAccessApiUsageException
报错:org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in r ...