您的位置首页生活百科

[Android]可展开的列表组件 ExpandableListView

[Android]可展开的列表组件 ExpandableListView

的有关信息介绍如下:

[Android]可展开的列表组件 ExpandableListView

ExpandableListView继承自ListVie,它把应用中的列表分为几组,每组又包含多个列表项,实现可展开的列表。

列表项由ExpandableListAdapter提供。

实现ExpandableAdapter的三种方式

1.扩展BaseExpandableListAdpter实现ExpandableAdapter。

2.使用SimpleExpandableListAdpater将两个List集合包装成ExpandableAdapter

3.是使用simpleCursorTreeAdapter将Cursor中的数据包装成SimpleCuroTreeAdapt

本例采用第一种方式实现

ExpandableListView额外支持的xml属性

编写布局文件

建立数组,用于列表展示

创建私有方法,用于各级列表项的显示

扩展BaseExpandableListAdapter来实现ExpandableListAdapter

关键是实现getGroupView(),getChildView()两方法

完整代码及部分说明

效果图