Android ExpandableListView的使用
2012-07-31 11:51
323 查看
展开型列表控件,原名ExpandableListView 是普通的列表控件进阶版, 可以自由的把列表进行收缩。
下面是实现后的截图:
一、界面设计
该控件的实现需要一个主界面main.xml、一个标题界面groups.xml、以及一个列表内容界面childs.xml。
(1)首先我们来看看main.xml主界面,只需要一个ExpandableListView即可:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ExpandableListView
android:id="@id/android::list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
(2)标题界面groups.xml,只需要一个标题TextView控件上去即可。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/textGroup"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="40px"
android:paddingTop="6px"
android:paddingBottom="6px"
android:textSize="15sp"
android:text="No data"
/>
</LinearLayout>
(3)列表内容控件childs.xml,是子控件,直接显示列表内容
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/textChild"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="60px"
android:paddingTop="10px"
android:paddingBottom="10px"
android:textSize="20sp"
android:text="No Data"
/>
</LinearLayout>
二、实现的主代码
下面给出具体的实现代码:
public
class ExpandActivity
extends ExpandableListActivity
{
@Override
public
void onCreate(Bundle
savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//创建二个一级条目标题
Map<String,
String>
title_1 =
new HashMap<String,
String>();
Map<String,
String>
title_2 =
new HashMap<String,
String>();
title_1.put("group",
"开发");
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>();
Map<String,
String>
content_2 =
new HashMap<String,
String>();
content_1.put("child",
"VC++");
content_2.put("child",
"Java");
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>();
Map<String,
String>
content_4 =
new HashMap<String,
String>();
content_3.put("child",
"敏捷开发");
下面是实现后的截图:
一、界面设计
该控件的实现需要一个主界面main.xml、一个标题界面groups.xml、以及一个列表内容界面childs.xml。
(1)首先我们来看看main.xml主界面,只需要一个ExpandableListView即可:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ExpandableListView
android:id="@id/android::list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
(2)标题界面groups.xml,只需要一个标题TextView控件上去即可。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/textGroup"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="40px"
android:paddingTop="6px"
android:paddingBottom="6px"
android:textSize="15sp"
android:text="No data"
/>
</LinearLayout>
(3)列表内容控件childs.xml,是子控件,直接显示列表内容
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/textChild"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="60px"
android:paddingTop="10px"
android:paddingBottom="10px"
android:textSize="20sp"
android:text="No Data"
/>
</LinearLayout>
二、实现的主代码
下面给出具体的实现代码:
public
class ExpandActivity
extends ExpandableListActivity
{
@Override
public
void onCreate(Bundle
savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//创建二个一级条目标题
Map<String,
String>
title_1 =
new HashMap<String,
String>();
Map<String,
String>
title_2 =
new HashMap<String,
String>();
title_1.put("group",
"开发");
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>();
Map<String,
String>
content_2 =
new HashMap<String,
String>();
content_1.put("child",
"VC++");
content_2.put("child",
"Java");
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>();
Map<String,
String>
content_4 =
new HashMap<String,
String>();
content_3.put("child",
"敏捷开发");
相关文章推荐
- Android中ExpandableListView的使用
- Android ExpandableListView使用指南
- Android中ExpandableListView的使用(二)
- Android ExpandableListview使用gson解析树形结构数据。
- Android开发之ExpandableListView扩展(BaseExpandableListAdapter的使用)(完整版)
- Android中ExpandableListView的使用
- android中的ExpandableListView使用
- Android中ExpandableListView的使用详解
- android开发之--ExpandableListView控件使用心得
- android编程之ExpandableListView使用总结
- Android ExpandableListView 使用要点笔记
- 仿QQ列表--Android控件ExpandableListView的使用
- android ExpandableListView三级菜单的使用
- android下ExpandableListView的详细使用demo
- Android ExpandableListView使用小结(二)
- Android在ExpandableListView控制的基本使用
- Android:ExpandableListView使用
- android 高级之旅 (六)ExpandableListView 使用详解
- android中ExpandableListView嵌套GridView使用
- Android ExpandableListView使用