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 组件来显示专家分类,每个分类点击之后可以显示专家的头像和名字. 很简单 ...
 
随机推荐
- 导出Excel事例
			
DataTable table = new DataTable(); StringWriter sw = new StringWriter(); string tabltitle = "客户 ...
 - SQL 树结构统计数据
			
create table #Tmp( ID int IDENTITY (1,1) not null, name varchar(50), sl int); DECLARE @ID VARCHAR(36 ...
 - 使用Linq 来解决Datatable 去除数据重复
			
在这也说明下,除此之外还可以通过 DataView 的方式来处理,当个人觉得这有点不好用.这里就不多作说明了 代码比较简单,直接看代码 using System; using System.Colle ...
 - SAX方式解析XML文件实例
			
books.XML文件: 书籍book.java实体类: public class Book { private String id; private String name; private Str ...
 - asp:保留两位小数:
			
<%=Formatnumber(-6665.8999,3,-1,-1,0)%>(6665.900)一个例子用到了函数Formatnumber()的所有参数:第一个参数(-6665.8999 ...
 - Oracle每10天删除数据,并重建索引
			
declare datDateFrom date := to_date('2010/08/01 00:00:00','yyyy/mm/dd hh24:mi:ss'); datDateTo date; ...
 - C++(指针)
			
指针在编程中有时很重要的作用 我们可以用它完成一些看似不可能完成的任务 #include<iostream>using namespace std;void square(int *n){ ...
 - linux中的sticky bit
			
今天看到有个目录的权限是rwxrwxrwt 很惊讶这个t是什么,怎么不是x或者-呢?搜了下发现: 这个t代表是所谓的sticky bit. sticky bit: 该位可以理解为防删除位. 一个文件是 ...
 - sql 自定义排序
			
方法一: 比如需要对SQL表中的字段NAME进行如下的排序: 张三(Z) 李四(L) 王五(W) 赵六(Z) 按照sql中的默认排序规则,根据字母顺序(a~z)排,结果为:李四 王五 赵六 张三 ...
 - TweenMax动画库学习(二)
			
目录 TweenMax动画库学习(一) TweenMax动画库学习(二) TweenMax动画库学习(三) Tw ...