2011-04-26 12:51:55
ExpandableListActivity 与ExpandableListView的关系就向 ListActivity与ListView一样总是一起出现的
先上个个效果图
1.首先在main.xml添加ExpandableListView
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns: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" //ExpandableListView的ID为Android自定义,不可改变 android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/background"/> </LinearLayout>
2.为父目录创建布局文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:id="@+id/parent_group" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="8px" android:paddingLeft="50px" android:paddingBottom="6px" android:textColor="#ff00ff" android:textStyle="bold"/> </LinearLayout>
3.为子目录创建布局文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="20dp" android:orientation="horizontal"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="20px" android:paddingTop="4dp" android:background="@drawable/child_image"/> <LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:id="@+id/child_group" android:textSize="20sp" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="地址:xx省xx市xx"/> </LinearLayout> </LinearLayout>
4.DisplayExpandableList.java
package com.yin; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import android.app.ExpandableListActivity; import android.os.Bundle; import android.widget.ExpandableListAdapter; import android.widget.ExpandableListView; import android.widget.SimpleExpandableListAdapter; public class DisplayExpandableList extends ExpandableListActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); List<HashMap<String, String>> parent_groups = new ArrayList<HashMap<String, String>>(); String[] parent_group_names = {"我的好友","初中同学","高中同学","大学同学","黑名单"}; parent_groups = this.addParentItems(parent_groups, parent_group_names); List<List<HashMap<String, String>>> child_groups = new ArrayList<List<HashMap<String, String>>>(); List<HashMap<String, String>> child_lists = new ArrayList<HashMap<String, String>>(); child_groups = this.addChildsItems(child_groups, child_lists, "小华"); /** * SimpleExpandableListAdapter的参数那是相当的多啊 * 参数 1:context * 2:父级目录的数据 * 3:父级目录的布局文件 * 4: 夫级目录的数据来源 * 5:指定父级目录显示数据的控件 * 6:子级目录的数据 * 7:子级目录的布局文件 * 8:子级目录的数据来源 * 9:指定子级目录显示数据的控件 */ SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter( this, parent_groups, R.layout.parent_layout, new String[]{"parent_group"}, new int[]{R.id.parent_group}, child_groups, R.layout.child_layout, new String[]{"child_group"}, new int[]{R.id.child_group}); setListAdapter(adapter); } //为每个父母目录下子目录添加数据 public List<List<HashMap<String, String>>> addChildsItems( List<List<HashMap<String, String>>> child_groups, List<HashMap<String, String>> child_list, String item) { child_groups = new ArrayList<List<HashMap<String, String>>>(); child_list = new ArrayList<HashMap<String, String>>(); HashMap<String, String> map = new HashMap<String, String>(); map.put("child_group", item); child_list.add(map); child_groups.add(child_list); return child_groups; } //为父级目录分组,添加标识 public List<HashMap<String, String>> addParentItems( List<HashMap<String, String>> parent_groups, String[] parent_group_names) { parent_groups = new ArrayList<HashMap<String, String>>(); for(int i=0;i<parent_group_names.length;i++){ HashMap<String, String> groups = new HashMap<String, String>(); groups.put("parent_group", parent_group_names[i]); parent_groups.add(groups); } return parent_groups; } }
您还没有登录,请您登录后再发表评论
`ExpandableListActivity`是Android开发中的一个关键组件,它属于`ListView`的扩展,能够显示可折叠的子列表项,使得用户界面更加有层次感和交互性。在这个主题下,我们将深入探讨`ExpandableListActivity`的工作...
在Android开发中,`ExpandableListActivity`是一个用于展示可扩展列表的特殊活动。这个类是基于`ListView`的,但提供了更复杂的功能,允许用户显示分组数据,每个分组下还可以有多个子项。在给定的...
`ExpandableListActivity`是Android框架中用于显示层次结构数据的Activity。与传统的`ListActivity`不同,它能够展示多层级的数据,即可以有父项和子项的概念。用户可以通过点击父项来展开或折叠其子项列表,非常...
PreferenceActivity和ExpandableListActivity的使用,详细了解请移步:http://blog.csdn.net/zxc514257857/article/details/77773001
* @see android.app.ExpandableListActivity#onCreateContextMenu(android.view.ContextMenu, android.view.View, android.view.ContextMenu.ContextMenuInfo) */ @Override public void onCreateContextMenu...
【Android火星视频教程笔记概述】 ...这些文档构成了Android开发的基础知识框架,从UI交互到后台数据处理,覆盖了开发者在实际项目中可能遇到的各种场景。通过深入理解和实践,能够提升Android应用开发的专业技能。
import android.app.ExpandableListActivity; import android.os.Bundle; public class MainActivity extends ExpandableListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super...
在Android中,我们可以使用`ExpandableListActivity`或者普通的`Activity`配合`ExpandableListView`进行布局。数据通常由`ExpandableListAdapter`管理,这个适配器需要实现`BaseExpandableListAdapter`接口。 在...
这个`Android应用源码之expandableList1_expandableList.zip`文件包含了关于如何使用ExpandableListView的一个示例源码。通过分析和学习这个源码,我们可以深入了解该控件的工作原理和实现方法。 首先,...
`ExpandableListView`通常与`ExpandableListActivity`一起使用,就像`ListActivity`与`ListView`的关系一样。 首先,我们需要创建一个包含`ExpandableListView`的布局。在`main.xml`中,你可以看到以下代码: ```...
在Android应用开发中,`ExpandableListView`是一个非常有用的控件,它允许用户展示一个可折叠/展开的列表,这种列表通常用于显示层次结构的数据,如目录结构、菜单或者RSS阅读器中的文章分类。在这个例子中,我们...
#### Android—基础 ##### 基础—概念 - **控件类之父**:`View`是所有控件的基类,无论是简单的按钮还是复杂的列表视图,都是从这个类派生出来的。 - **基准线**:在英文书写中,通常使用四线格来辅助书写,其中第...
### Android开发笔记知识点详解 #### 第1章 Android简介 ...以上总结了Android开发笔记中的核心知识点,涵盖了从基础概念到具体实践的多个方面。这些内容对于初学者理解和掌握Android开发非常有帮助。
在我们的示例代码中,我们创建了一个 ActivityMain 类,该类继承自 ExpandableListActivity,并实现了 onCreate()、onCreateContextMenu() 和 onContextItemSelected() 等方法。这些方法负责初始化列表控件、创建上...
Android控件下拉框,单选按钮,复选框,自动补全,日期控件(支持显示格式:年月,年月日,月日),LauncherActivity的使用,ExpandableListActivity实现二级下拉列表,并且在列表项右边加自定义的图片,实现只展开一个菜单的功能...
在提供的代码示例中,我们看到`Chapter9Tutorial4`扩展了`ExpandableListActivity`,这是一个专为ExpandableListView设计的Activity基类。在`onCreate`方法中,我们需要设置两个关键的数据结构:`groupData`和`...
在Android应用开发中,创建一个个人理财工具是一个实用且具有挑战性的任务。本文将探讨如何在这样的工具中实现添加账单页面,这是一个关键功能,允许用户记录他们的收入和支出。在这一部分,我们将关注界面设计、...
在Android开发中,`ExpandableListView` 是一个非常实用的控件,它可以显示具有扩展功能的列表,即每个条目可以展开以显示更多的子条目,通常用于构建具有层级结构的数据展示。本教程将深入讲解如何在Android应用中...
接下来是关键的Java代码,通常继承自`ExpandableListActivity`或者自定义的`BaseExpandableListAdapter`。这里,`ExpandActivity`类负责设置`ExpandableListView`的数据源和适配器。`onCreate`方法是初始化的关键点...
(2)第二种方法则是创建一个Activity继承自ExpandableListActivity,而后通过getExpandableListView()方法可获得一个ExpandableListView对象。 第二种方法仅适用于一个页面中只有一个ExpandableListView的情况。...
相关推荐
`ExpandableListActivity`是Android开发中的一个关键组件,它属于`ListView`的扩展,能够显示可折叠的子列表项,使得用户界面更加有层次感和交互性。在这个主题下,我们将深入探讨`ExpandableListActivity`的工作...
在Android开发中,`ExpandableListActivity`是一个用于展示可扩展列表的特殊活动。这个类是基于`ListView`的,但提供了更复杂的功能,允许用户显示分组数据,每个分组下还可以有多个子项。在给定的...
`ExpandableListActivity`是Android框架中用于显示层次结构数据的Activity。与传统的`ListActivity`不同,它能够展示多层级的数据,即可以有父项和子项的概念。用户可以通过点击父项来展开或折叠其子项列表,非常...
PreferenceActivity和ExpandableListActivity的使用,详细了解请移步:http://blog.csdn.net/zxc514257857/article/details/77773001
* @see android.app.ExpandableListActivity#onCreateContextMenu(android.view.ContextMenu, android.view.View, android.view.ContextMenu.ContextMenuInfo) */ @Override public void onCreateContextMenu...
【Android火星视频教程笔记概述】 ...这些文档构成了Android开发的基础知识框架,从UI交互到后台数据处理,覆盖了开发者在实际项目中可能遇到的各种场景。通过深入理解和实践,能够提升Android应用开发的专业技能。
import android.app.ExpandableListActivity; import android.os.Bundle; public class MainActivity extends ExpandableListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super...
在Android中,我们可以使用`ExpandableListActivity`或者普通的`Activity`配合`ExpandableListView`进行布局。数据通常由`ExpandableListAdapter`管理,这个适配器需要实现`BaseExpandableListAdapter`接口。 在...
这个`Android应用源码之expandableList1_expandableList.zip`文件包含了关于如何使用ExpandableListView的一个示例源码。通过分析和学习这个源码,我们可以深入了解该控件的工作原理和实现方法。 首先,...
`ExpandableListView`通常与`ExpandableListActivity`一起使用,就像`ListActivity`与`ListView`的关系一样。 首先,我们需要创建一个包含`ExpandableListView`的布局。在`main.xml`中,你可以看到以下代码: ```...
在Android应用开发中,`ExpandableListView`是一个非常有用的控件,它允许用户展示一个可折叠/展开的列表,这种列表通常用于显示层次结构的数据,如目录结构、菜单或者RSS阅读器中的文章分类。在这个例子中,我们...
#### Android—基础 ##### 基础—概念 - **控件类之父**:`View`是所有控件的基类,无论是简单的按钮还是复杂的列表视图,都是从这个类派生出来的。 - **基准线**:在英文书写中,通常使用四线格来辅助书写,其中第...
### Android开发笔记知识点详解 #### 第1章 Android简介 ...以上总结了Android开发笔记中的核心知识点,涵盖了从基础概念到具体实践的多个方面。这些内容对于初学者理解和掌握Android开发非常有帮助。
在我们的示例代码中,我们创建了一个 ActivityMain 类,该类继承自 ExpandableListActivity,并实现了 onCreate()、onCreateContextMenu() 和 onContextItemSelected() 等方法。这些方法负责初始化列表控件、创建上...
Android控件下拉框,单选按钮,复选框,自动补全,日期控件(支持显示格式:年月,年月日,月日),LauncherActivity的使用,ExpandableListActivity实现二级下拉列表,并且在列表项右边加自定义的图片,实现只展开一个菜单的功能...
在提供的代码示例中,我们看到`Chapter9Tutorial4`扩展了`ExpandableListActivity`,这是一个专为ExpandableListView设计的Activity基类。在`onCreate`方法中,我们需要设置两个关键的数据结构:`groupData`和`...
在Android应用开发中,创建一个个人理财工具是一个实用且具有挑战性的任务。本文将探讨如何在这样的工具中实现添加账单页面,这是一个关键功能,允许用户记录他们的收入和支出。在这一部分,我们将关注界面设计、...
在Android开发中,`ExpandableListView` 是一个非常实用的控件,它可以显示具有扩展功能的列表,即每个条目可以展开以显示更多的子条目,通常用于构建具有层级结构的数据展示。本教程将深入讲解如何在Android应用中...
接下来是关键的Java代码,通常继承自`ExpandableListActivity`或者自定义的`BaseExpandableListAdapter`。这里,`ExpandActivity`类负责设置`ExpandableListView`的数据源和适配器。`onCreate`方法是初始化的关键点...
(2)第二种方法则是创建一个Activity继承自ExpandableListActivity,而后通过getExpandableListView()方法可获得一个ExpandableListView对象。 第二种方法仅适用于一个页面中只有一个ExpandableListView的情况。...