使用 ExpandableListView 实现折叠ListView
1:layout/expandablelistview_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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:paddingLeft="40dp"
android:text="标题:" />
<TextView
android:id="@+id/tvEmailTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="承运人自有车辆、船舶及营运资质通知" />
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:paddingLeft="40dp"
android:text="发件人:" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我"/>
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:paddingLeft="40dp"
android:text="时间:" />
<TextView
android:id="@+id/tvEmailSendTimes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2013-11-11 19:25:16"/>
</LinearLayout>
</LinearLayout>
2:layout/expandablelistview_child.xml 展开文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tvEmailContent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:lineSpacingExtra="2dp"
android:lineSpacingMultiplier="1.2"
android:text="this is content" />
</LinearLayout>
3:MainActivity.java
public class MainActivity extends Activity {
private ExpandableListView expandableListView_one;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
expandableListView_one =(ExpandableListView)findViewById(R.id.expandableListView);
//expandableListView.setDivider();这个是设定每个Group之间的分割线。
//expandableListView.setGroupIndicator();这个是设定每个Group之前的那个图标。
//创建二个一级条目标题
Map<String, String> title_1 = new HashMap<String, String>();
Map<String, String> title_2 = new HashMap<String, String>();
title_1.put("tvEmailTitle", "第一封邮件");
title_1.put("tvEmailSendTimes", "2013-11-11 20:08:20");
title_2.put("tvEmailTitle", "第二封邮件");
title_2.put("tvEmailSendTimes", "2013-11-11 20:08:20");
//创建一级条目容器
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>();
String str="您好,R.java是项目中所有资源文件的索引文件,是由系统自动生成,不需要开发者手动的编辑。";
content_1.put("tvEmailContent", str);
List<Map<String, String>> childs_1 = new ArrayList<Map<String,String>>();
childs_1.add(content_1);
//内容一
Map<String, String> content_2 = new HashMap<String, String>();
content_2.put("tvEmailContent", str);
List<Map<String, String>> childs_2 = new ArrayList<Map<String,String>>();
childs_2.add(content_2);
//存放两个内容, 以便显示在列表中
List<List<Map<String, String>>> childs = new ArrayList<List<Map<String,String>>>();
childs.add(childs_1);
childs.add(childs_2);
/*
使用SimpleExpandableListAdapter显示ExpandableListView
参数1.上下文对象Context
参数2.一级条目目录集合
参数3.一级条目对应的布局文件 (expandablelistview_groups.xml文件
参数4.标题,map中的key,指定要显示的对象
参数5.与参数4对应,指定要显示在groups中的id
参数6.二级条目目录集合
参数7.二级条目对应的布局文件 (expandablelistview_child)
参数8.展开内容,map中的key,指定要显示的对象
参数9.与参数8对应,指定要显示在childs中的id
*/
SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter(
this,
groups,
R.layout.expandablelistview_groups,
new String[]{"tvEmailTitle", "tvEmailSendTimes"},
new int[]{R.id.tvEmailTitle, R.id.tvEmailSendTimes},
childs,
R.layout.expandablelistview_child,
new String[]{"tvEmailContent"},
new int[]{R.id.tvEmailContent}
);
//将适配器加入列表
expandableListView_one.setAdapter(adapter);
//注册事件
expandableListView_one.setOnChildClickListener(listener);
}
private OnChildClickListener listener = new OnChildClickListener(){
@Override
public boolean onChildClick(ExpandableListView arg0, View arg1,
int arg2, int arg3, long arg4) {
Toast.makeText(MainActivity.this, "ok", Toast.LENGTH_SHORT).show();
return false;
}
};
}
使用 ExpandableListView 实现折叠ListView的更多相关文章
- Android 高级UI设计笔记01:使用ExpandableListView组件(ListView的扩展)
1.ExpandableListView是一个用来显示二级节点的ListView. 比如如下效果的界面: 2.使用ExpandableListView步骤 (1)要给ExpandableListVie ...
- 折叠ListView
转自 http://blog.csdn.net/hnyzwtf/article/details/50487228 1 activity_main.xml <?xml version=" ...
- ListView的属性及方法详解
本文转载于:http://blog.csdn.net/vector_yi/article/details/23195411 近期在重新学习Android控件知识,目前进行到ListView,感觉这是一 ...
- Android常用控件之GridView与ExpandableListView的用法
概述 1.GridView:与ListView相比,可以显示多列,xml布局时其属性numColumns可以设置显示的列数. 2.ExpandableListView:与ListView相比,可以让每 ...
- 安卓第六天笔记--ListView
安卓第六天笔记--ListView 1.AdapteView AdapteView 继承ViewGroup它的本质是容器 AdapterView派生了3个子类: AbsListView AbsSpin ...
- Android 关于ExpandableListView刷新的解决办法
正文 首先是最基础的 ExpandableListView vList = (ExpandableListView) this.findViewById(R.id.list); EListAdapte ...
- Android之ExpandableListView的属性(Group不展开)
1. 设置ExpandableListView 默认是展开的: 先实例化exListView 然后 exListView.setAdapter(exlvAdapter); //遍历所有group,将 ...
- Android ExpandableListView和ScrollView联用的一些注意事项
之前有整理过ScrollView嵌套ListView的例子,讲的是计算listview的每一项的高度.已达到目标效果.同样的ExpandableListView嵌套ScrollView也是这么个思路, ...
- 第十四章:样式(Style)和主题(Theme)
简介 Android的样式(Style)和主题(Theme)文件就好比WEB开发中的CSS一样,可以实现UI界面的风格统一管理,这和Windows平台的XAML格式(Silverlight.WPF)类 ...
随机推荐
- 用Setup系列函数完成驱动卸载安装[驱动安装卸载程序]
// InstallWDFDriver.cpp : Defines the entry point for the console application. // #include "std ...
- Java JDBC中,MySQL字段类型到JAVA类型的转换
1. 概述 在使用Java JDBC时,你是否有过这样的疑问:MySQL里的数据类型到底该选择哪种Java类型与之对应?本篇将为你揭开这个答案. 2. 类型映射 java.sql.Types定义了常 ...
- 什么是Ajax? (转载于疯狂客的BLOG)
Ajax的定义 Ajax不是一个技术,它实际上是几种技术,每种技术都有其独特这处,合在一起就成了一个功能强大的新技术. Ajax包括: XHTML和CSS,使用文档对象模型(Document Obje ...
- HDU_1238——最大子串搜索
Problem Description You are given a number of case-sensitive strings of alphabetic characters, find ...
- python部落刷题宝学到的内置函数(二)
感觉到刷题宝有一个好处,也许也不是好处,它的答案必须是真正输出的值,也就是说应该输出字符串aaaa的时候,答案必须写成界面上返回的值,即'aaaa'.有利于真正记忆返回值类型,但是....太繁琐了 1 ...
- WingIDE注册破解方法
WingIDE是Python程序语言设计的集成开发环境,具有语法标签高亮显示,命令自动完成和函数跳转列表等非常强大的功能.本文主要介绍WingIDE 5安装及注册破解方法. 1. WingIDE 5下 ...
- JS浏览器对象-Screen对象
代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title ...
- 解析Xcode把应用程序打包成ipa---解决打包完新版本itunes提示不是有效应用程序的问题
Xcode把应用程序打包成ipa是本文要介绍的内容,不多说,先俩看内容.注意:本方法需要先制作假凭证编译于项目中,否则产生的ipa还是无法于iPhone中运行. 制作方法请参考: http://blo ...
- Servlet问题:servlet cannot be resolved to a type解决办法
工程里的路径权限高,并且eclipse并到classpath里寻找jar位置,所以我就到我的java项目里 项目名-->右键 Property-->选择 Java Build Path-- ...
- Qt的Graphics-View框架和OpenGL结合详解
Qt的Graphics-View框架和OpenGL结合详解 演示程序下载地址:这里 程序源代码下载地址:这里 这是一篇纯技术文,介绍了这一个月来我抽时间研究的成果. Qt中有一个非常炫的例子:Boxe ...