`
Bauble
  • 浏览: 66944 次
  • 性别: Icon_minigender_1
  • 来自: Mercury
社区版块
存档分类
最新评论

Android28_ExpandableListActivity

阅读更多

 

ExpandableListActivity就是可扩展的list,单击某个item后,又可显示一个子list。它的数据通过绑定到ExpandableListAdapter或者ExpandableListAdapter的子类上。

       1.在主(main.xml)布局文件中声明ExpandableListActivity控件:

 

<ExpandableListView android:id="@id/android:list" 
    	android:layout_width="fill_parent"
    	android:layout_height="fill_parent"/>

        2.在组(group.xml)布局文件中声明group样式:

 

<TextView android:id="@+id/group" 
		android:layout_width="fill_parent"
		android:layout_height="fill_parent" 
		android:paddingLeft="60px" 
		android:paddingTop="10px"
		android:paddingBottom="10px" 
		android:textSize="26sp" />

        3.在子(child.xml)布局文件中声明子条目的样式:

 

<TextView android:id="@+id/subitem" 
		android:layout_width="fill_parent"
		android:layout_height="fill_parent" 
		android:paddingLeft="60px" 
		android:paddingTop="10px"
		android:paddingBottom="10px" 
		android:textSize="20sp" />

        4.创建Activity,并继承ExpandableListActivity

 

public class ExpandableListViewActivity extends ExpandableListActivity{}

5.group创建数据:

 

//定义group的list
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);

        6.child创建数据:

 

        //定义group下的子条目
        List<Map<String,String>> subItem1 = new ArrayList<Map<String,String>>();
        Map<String,String> item11 = new HashMap<String, String>();
        item11.put("item", "第一条");
        Map<String,String> item12 = new HashMap<String,String>();
        item12.put("item", "第二条");
        subItem1.add(item11);
        subItem1.add(item12);
        
        List<Map<String,String>> subItem2 = new ArrayList<Map<String,String>>();
        Map<String,String> item21 = new HashMap<String, String>();
        item21.put("item", "第一条");
        Map<String,String> item22 = new HashMap<String,String>();
        item22.put("item", "第二条");
        Map<String,String> item23 = new HashMap<String,String>();
        item23.put("item", "第三条");
        subItem2.add(item21);
        subItem2.add(item22);
        subItem2.add(item23);
        
        List<List<Map<String,String>>> subItems = new ArrayList<List<Map<String,String>>>();
        subItems.add(subItem1);
        subItems.add(subItem2);

 创建SimpleExpandableListAdapter的步骤

 

	SimpleExpandableListAdapter s = new SimpleExpandableListAdapter(
        		this, groups, R.layout.group, new String[]{"group"}, 
        		new int[]{R.id.group},subItems, R.layout.subitem, 
			new String[]{"item"}, new int[]{R.id.subitem});
    	setListAdapter(s);

 Adapter构造方法共有9个参数,分别为:(1Context.2)一级条目的数据(3)一级条目的布局(4)一级条目的key5)一级条目的数据显示控件的id6)二级条目的数据(7)二级条目的布局(8)二级条目数据的key9)二级条目数据控件的id

运行结果:



  • 大小: 30.6 KB
  • 大小: 37.1 KB
分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

    ExpandableListActivity

    `ExpandableListActivity`是Android开发中的一个关键组件,它属于`ListView`的扩展,能够显示可折叠的子列表项,使得用户界面更加有层次感和交互性。在这个主题下,我们将深入探讨`ExpandableListActivity`的工作...

    ExpandableListActivity例子,自动展开

    在Android开发中,`ExpandableListActivity`是一个用于展示可扩展列表的特殊活动。这个类是基于`ListView`的,但提供了更复杂的功能,允许用户显示分组数据,每个分组下还可以有多个子项。在给定的...

    ExpandableListActivity和SimpleExpandableListAdapter的基本使用详解

    `ExpandableListActivity`是Android框架中用于显示层次结构数据的Activity。与传统的`ListActivity`不同,它能够展示多层级的数据,即可以有父项和子项的概念。用户可以通过点击父项来展开或折叠其子项列表,非常...

    Android仿QQ好友列表实现列表收缩与展开

    import android.app.ExpandableListActivity; import android.os.Bundle; public class MainActivity extends ExpandableListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super...

    android 的类似于QQ分组的二级列表

    * @see android.app.ExpandableListActivity#onCreateContextMenu(android.view.ContextMenu, android.view.View, android.view.ContextMenu.ContextMenuInfo) */ @Override public void onCreateContextMenu...

    android的ExpandableListView组件.doc

    `ExpandableListView`通常与`ExpandableListActivity`一起使用,就像`ListActivity`与`ListView`的关系一样。 首先,我们需要创建一个包含`ExpandableListView`的布局。在`main.xml`中,你可以看到以下代码: ```...

    Android应用源码之expandableList1_expandableList.zip

    在`ExpandableListActivity.java`或类似的文件中,你需要创建一个自定义的Adapter类,继承自`BaseExpandableListAdapter`,并实现其方法如`getGroupCount()`、`getChildrenCount(int groupPosition)`、`getGroup(int...

    Mars Android视频教程的笔记

    5. **ExpandableListActivity.doc** - ExpandableListView是一种可扩展的列表视图,能展示层级结构的数据。这部分讲述了如何创建和管理子项,以及监听和响应用户的展开和折叠操作。 6. **ContentProvider.doc** - ...

    Android-ExpandableListView制作时间轴-TimeLine

    在Android中,我们可以使用`ExpandableListActivity`或者普通的`Activity`配合`ExpandableListView`进行布局。数据通常由`ExpandableListAdapter`管理,这个适配器需要实现`BaseExpandableListAdapter`接口。 在...

    android列表控件实现展开、收缩功能

    在我们的示例代码中,我们创建了一个 ActivityMain 类,该类继承自 ExpandableListActivity,并实现了 onCreate()、onCreateContextMenu() 和 onContextItemSelected() 等方法。这些方法负责初始化列表控件、创建上...

    Android支持展开和收缩功能的列表控件[汇编].pdf

    在Android应用开发中,`ExpandableListView`是一个非常有用的控件,它允许用户展示一个可折叠/展开的列表,这种列表通常用于显示层次结构的数据,如目录结构、菜单或者RSS阅读器中的文章分类。在这个例子中,我们...

    android安卓笔记

    ### Android 安卓笔记知识点详解 #### Android—基础 ##### 基础—概念 - **控件类之父**:`View`是所有控件的基类,无论是简单的按钮还是复杂的列表视图,都是从这个类派生出来的。 - **基准线**:在英文书写中,...

    分享Android中ExpandableListView控件使用教程

    在Android开发中,`ExpandableListView` 是一个非常实用的控件,它可以显示具有扩展功能的列表,即每个条目可以展开以显示更多的子条目,通常用于构建具有层级结构的数据展示。本教程将深入讲解如何在Android应用中...

    Android学习笔记(二五): 多信息显示-ExpandableListView的使用.doc

    在提供的代码示例中,我们看到`Chapter9Tutorial4`扩展了`ExpandableListActivity`,这是一个专为ExpandableListView设计的Activity基类。在`onCreate`方法中,我们需要设置两个关键的数据结构:`groupData`和`...

    android学习实例

    Android控件下拉框,单选按钮,复选框,自动补全,日期控件(支持显示格式:年月,年月日,月日),LauncherActivity的使用,ExpandableListActivity实现二级下拉列表,并且在列表项右边加自定义的图片,实现只展开一个菜单的功能...

    Android 个人理财工具三:添加账单页面 上

    在Android应用开发中,创建一个个人理财工具是一个实用且具有挑战性的任务。本文将探讨如何在这样的工具中实现添加账单页面,这是一个关键功能,允许用户记录他们的收入和支出。在这一部分,我们将关注界面设计、...

    Android ExpandableListView展开列表控件使用实例

    接下来是关键的Java代码,通常继承自`ExpandableListActivity`或者自定义的`BaseExpandableListAdapter`。这里,`ExpandActivity`类负责设置`ExpandableListView`的数据源和适配器。`onCreate`方法是初始化的关键点...

    ExpandableListView实现手风琴效果

    (2)第二种方法则是创建一个Activity继承自ExpandableListActivity,而后通过getExpandableListView()方法可获得一个ExpandableListView对象。 第二种方法仅适用于一个页面中只有一个ExpandableListView的情况。...

Global site tag (gtag.js) - Google Analytics