仿qq联系人 学习笔记---ExpandableListActivity的使用
【转】原地址 http://blog.163.com/xygzx@126/blog/static/237809502011102010100331/
效果显示图:

1.布局文件
main.xml(ExpandableListActivity布局文件)
注意事项:
ExpandableListActivity的布局文件中必须包含一个ExpandableListView,并且id必须为="@id/android:list"。还可以包含一个id为empty的TextView,在ExpandableListActivity中没有数据的时候显示该控件的text值。
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ExpandableListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false">
</ExpandableListView>
<TextView
android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="没有数据">
</TextView>
</LinearLayout>
group.xml(一级条目布局文件,样式外观可根据需要自由发挥)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/groupTo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="60dip"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:text="No Date"
android:textSize="20sp">
</TextView>
</LinearLayout>
child.xml(二级条目布局文件,样式外观可根据需要自由发挥)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/childTo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="50dip"
android:paddingTop="5dip"
android:paddingBottom="5dip"
android:textSize="20sp"
android:text="No Date">
</TextView>
</LinearLayout>
2.JAVA代码
package com.test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.widget.SimpleExpandableListAdapter;
public class Sample_ExpandableListActivityActivity extends ExpandableListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//一级条目
List<Map<String, String>>groups=new ArrayList<Map<String,String>>();
Map<String, String> group1=new HashMap<String, String>();
group1.put("group","第一组");
Map<String, String> group2=new HashMap<String, String>();
group2.put("group", "第二组");
groups.add(group1);
groups.add(group2);
//二组条目
List<List<Map<String, String>>> childs=new ArrayList<List<Map<String,String>>>();
//第一组二级科目数据
List<Map<String, String>> child1=new ArrayList<Map<String,String>>();
Map<String, String> item1=new HashMap<String, String>();
item1.put("child","科目-1");
Map<String, String> item2=new HashMap<String, String>();
item2.put("child","科目-2");
child1.add(item1);
child1.add(item2);
//第二组二级科目数据
List<Map<String, String>> child2=new ArrayList<Map<String,String>>();
Map<String, String> item3=new HashMap<String, String>();
item3.put("child","科目-3");
Map<String, String> item4=new HashMap<String, String>();
item4.put("child","科目-4");
Map<String, String> item5=new HashMap<String, String>();
item5.put("child","科目-5");
child2.add(item3);
child2.add(item4);
child2.add(item5);
childs.add(child1);
childs.add(child2);
//SimpleExpandableListAdapter构造函数参数
//1.content
//2.一级条目数据
//3.一级条目布局文件
//4.一级条目Key
//5.一级条目显示信息控件id
//6.二级条目数据
//7.二级条目布局文件
//8.二级条目Key
//9.二级条目显示信息控件id
SimpleExpandableListAdapter adapter=new SimpleExpandableListAdapter(this,groups,R.layout.group,
new String[]{"group"},new int[]{R.id.groupTo}, childs, R.layout.child, new String[]{"child"},
new int[]{R.id.childTo});
setListAdapter(adapter);
}
}
仿qq联系人 学习笔记---ExpandableListActivity的使用的更多相关文章
- WPF 自定义TreeView控件样式,仿QQ联系人列表
一.前言 TreeView控件在项目中使用比较频繁,普通的TreeView并不能满足我们的需求.因此我们需要滴对TreeView进行改造.下面的内容将介绍仿QQ联系人TreeView样式及TreeVi ...
- 动手分析安卓仿QQ联系人列表TreeView控件
因项目需要需要用到仿QQ联系人列表的控件样式,于是网上找到一个轮子(https://github.com/TealerProg/TreeView),工作完成现在简单分析一下这个源码. 一. 需要用 ...
- Android学习之仿QQ側滑功能的实现
如今项目越来越多的应用了滑动删除的功能,Android本来遵循的是长按删除,IOS定制的是滑动删除,不可否认滑动删除确实在客户体验上要好一点,所以看了非常多关于仿QQ滑动删除的样例,还是感觉代码家的A ...
- ArcGIS JS 学习笔记1 用ArcGIS JS 实现仿百度地图的距离量测和面积量测
一.开篇 在博客注册了三年,今天才决定写第一篇博客,警告自己不要懒!!! 二.关于ArcGIS JS 版本选择 在写这篇博客时ArcGIS JS 4.0正式版已经发布.它和3.x版本的不同是,Map不 ...
- android开发学习 ------- 仿QQ侧滑效果的实现
需要做一个仿QQ侧滑删除的一个效果: 一开始是毫无头绪,百度找思路,找到 https://blog.csdn.net/xiaxiazaizai01/article/details/53036994 ...
- C#仿QQ皮肤-Label与ListBox 控件实现----寻求滚动条的解决方案
大家还是先来看看效果吧 这次之所以一次写两个控件,其实主要是因为Label控件实在是太简单了没有必要放放一个文章里写,所以就一次性来了.Label控件我就不再多说了,我直接把代码贴一下吧因为就几行代码 ...
- SignalR快速入门 ~ 仿QQ即时聊天,消息推送,单聊,群聊,多群公聊(基础=》提升)
SignalR快速入门 ~ 仿QQ即时聊天,消息推送,单聊,群聊,多群公聊(基础=>提升,5个Demo贯彻全篇,感兴趣的玩才是真的学) 官方demo:http://www.asp.net/si ...
- knockout学习笔记目录
关于knockout学习系列的文章已经写完,这里主要是做个总结,并且将目录罗列出来,方便查看.欢迎各位大神拍砖和讨论. 总结 kncokout是一个轻量级的UI类库,通过MVVM模式使前端的UI简单话 ...
- WeX5学习笔记
目录 WeX5学习笔记... 1 1.轻松看透WeX5产品能力和技术... 1 2.WeX5可以怎么玩?... 3 一.纯本地App. 3 二.关联一个网站,希望默认就打开某页... 4 三.UI设计 ...
随机推荐
- VB.net Wcf事件广播(订阅、发布)
这篇东西原写在csdn.net上,最近新开通了博客想把零散在各处的都转移到一处. 一.源起 学WCF有一段时间了,可是无论是微软的WebCast还是其他网上的教程,亦或我购买的几本书中,都没有怎么 ...
- bzoj 1537: [POI2005]Aut- The Bus 线段树
bzoj 1537: [POI2005]Aut- The Bus 先把坐标离散化 设f[i][j]表示从(1,1)走到(i,j)的最优解 这样直接dp::: f[i][j] = max{f[i-1][ ...
- HTTP请求头
了解HTTP请求,是每个BS程序员必备的素质.下面篇幅进行记录.参考网址:http://tools.jb51.net/table/http_header Http请求方式 GET: 向Web服务器请求 ...
- Linux 下EXT2文件系统 —— 如何将蚂蚁和大象优雅的装进冰箱里
这一阵子真是偷懒,无时无刻不和自己身体中的懒癌做斗争.最终我还是被打败了,星期天两天几乎都是荒废过去的,在空闲的时候实际上我内心也是有点焦虑的,不知道去怎么度过这时间.学习吧又不想学习,看电视娱乐吧也 ...
- 使用VS2010创建WebService 发布、测试
http://blog.sina.com.cn/s/blog_45eaa01a0102vopl.html 1 打开VS2010,菜单 文件->新建->项目 2 选择[ASP.net ...
- PC工作原理
提到"技术"这个词时,大多数人都会想到计算机.事实上,我们生活中的方方面面都离不开计算机部件.家里的电器设备有内置的微处理器,例如电视机.甚至汽车里也装有计算机.但是,提到计算机大 ...
- Python 字符串操作及string模块使用
python的字符串操作通过2部分的方法函数基本上就可以解决所有的字符串操作需求: python的字符串属性函数 python的string模块 1.字符串属性方法操作: 1.>字符串格式输出对 ...
- CentOS7下搭建邮件服务器(dovecot + postfix + SSL)
CentOS 花了基本上两天的时间去配置CentOS7下的邮件服务器.其中艰辛太多了,一定得总结下. 本文的目的在于通过一系列配置,在CentOS 7下搭建dovecot + postfix + ...
- [Head First设计模式]生活中学设计模式——组合模式
系列文章 [Head First设计模式]山西面馆中的设计模式——装饰者模式 [Head First设计模式]山西面馆中的设计模式——观察者模式 [Head First设计模式]山西面馆中的设计模式— ...
- ThinkPHP3.2.3整合smarty模板(一)
一.php模板引擎有哪些? 1.1 PHPLIB:一套古老且主流的模板引擎,直接在html中使用PHP变量进行编程: 1.2 Template Blocks:一款轻巧且速度非常快的PHP模板引擎,支持 ...