BaseExpandableListAdpter分成了两部分:组和子列表
1、布局中的一些属性
android:childDivider:指定各组内子类表项之间的分隔条,图片不会完全显示, 分离子列表项的是一条直线
android:childIndicator:显示在子列表旁边的Drawable对象,可以是一个图像
android:childIndicatorEnd:子列表项指示符的结束约束位置
android:childIndicatorLeft:子列表项指示符的左边约束位置
android:childIndicatorRight:子列表项指示符的右边约束位置
android:childIndicatorStart:子列表项指示符的开始约束位置
android:groupIndicator:显示在组列表旁边的Drawable对象,可以是一个图像
android:indicatorEnd:组列表项指示器的结束约束位置
android:indicatorLeft:组列表项指示器的左边约束位置
android:indicatorRight:组列表项指示器的右边约束位置
android:indicatorStart:组列表项指示器的开始约束位置
2、创建保存组数据的集合,和保存子列表的集合
3、自定义适配器继承BaseExpandableListAdpter类
public class 自定义适配器 extends BaseExpandableListAdapter {
@Override
public int getGroupCount() {
//组
return 组的集合的长度;
}
@Override
public int getChildrenCount(int groupPosition) {
//子列表
return 子列表的集合的长度;
}
@Override
public Object getGroup(int groupPosition) {
return null;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return null;
}
@Override
public long getGroupId(int groupPosition) {
return 0;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return 0;
}
@Override
public boolean hasStableIds() {
return false;
}
//取得用于显示给定分组的视图. 这个方法仅返回分组的视图对象
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
return convertView;
}
//取得显示给定分组给定子位置的数据用的视图
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
return convertView;
}
//设置子列表是否可选中
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
}