ExpandableListActivity使用
使用方法(可以和ListActivity进行对比)
创建一个Activity类继承ExpandableListActvity
三个layout
主布局 (注意这里2个id都是android内置的 不是+id)
包含<ExpandableListView> 注意其中android:id="@id/android:list" 还有一个android:drawSelectorOnTop="false"(选中时是否遮盖文字)
<TextView android:id="@id/android:empty"> 当无数据时
一级目录布局
二级目录布局(条目item样式)
创建Adapter
将simpleExpandableListAdapter对象设置给当前ExpandableListActivity
setListAdapter(adapter);
SimpleExpandableListAdapter使用
为ExpandableListActivity提供数据
//定义List 为一级条目提供数据
List<Map<String, String>> groups=new ArrayList<Map<String, String>>();
需要几个条目 生成几个Map对象
Map<String, String> m1=new HashMap<String, String>();
m1.put(group,Group1);
m2.put(group,Group2);
groups.add(m1);
groups.add(m2);
//定义List 设置二级子条目 一个子条目一个List 一个项 一个Map
方法同上 建List(child1 child2)和Map(child:child1Data1;child:child1Data2)
//定义一个List 存储所有二级条目数据
*List<List<Map<String, String>>> childs = new ArrayListM<List<Map<String, String>>>();
childs.add(child1);
childs.add(child2);
//生成一个SimpleExpandableListAdapter对象
new SimpleExpandableListAdapter(...);
参数包括
(context上下文对象,一级条目List对象,一级条目布局,
new String[]{"groups"})指定一级条目数据的key,new int[]{R.id.groupTo}指定一级条目数据显示的控件id,
二级条目的数据childs,二级条目布局,二级条目数据key(child),二级条目控件id}
最终目录结构
Group1
child1Data1
child1Data2
Group2
child2Data
分享到:
相关推荐
ExpandableListActivity的基本例子,打开后每隔一秒展开一个item
NULL 博文链接:https://wang-peng1.iteye.com/blog/683156
ExpandableListActivity和SimpleExpandableListAdapter的基本使用详解
PreferenceActivity和ExpandableListActivity的使用,详细了解请移步:http://blog.csdn.net/zxc514257857/article/details/77773001
之前的博文《Android 中使用ExpandableListView 实现分组的实例》我简单介绍了使用ExpandableListView实现简单的好友分组功能,今天我们针对之前的所做的仿微信APP来对ExpandableListView做一个扩展介绍,实现效果...
import android.app.ExpandableListActivity; import android.os.Bundle; import android.provider.Contacts.People; import android.util.Log; import android.view.ContextMenu; import android.view.Gravity; ...
Android控件下拉框,单选按钮,复选框,自动补全,日期控件(支持显示格式:年月,年月日,月日),LauncherActivity的使用,ExpandableListActivity实现二级下拉列表,并且在列表项右边加自定义的图片,实现只展开一个菜单的功能...
(2)第二种方法则是创建一个Activity继承自ExpandableListActivity,而后通过getExpandableListView()方法可获得一个ExpandableListView对象。 第二种方法仅适用于一个页面中只有一个ExpandableListView的情况。...