ExpandableListView的收缩功能还是比较常见的。所以就使用了,然而要的效果是不要这个组左侧的图标+在右侧图标显示收起还是放下。
原因,主要是组的布局采用了checkbox控件导致的,只要在组布局控件加两个属性( android:clickable=”false” android:focusable=”false”)就可以了。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/divider_horizontal" />
<CheckBox
android:id="@+id/chk_group"
android:layout_width="match_parent"
android:layout_height="88px"
android:background="@color/white"
android:button="@null"
android:clickable="false"
android:drawableRight="@drawable/selector_dropdown"
android:focusable="false"
android:paddingLeft="30px"
android:paddingRight="40px"
android:text="基本参数"
android:textColor="@color/orange"
android:textSize="30px" />
</LinearLayout>
然而,这么样的话,就无法改变checkbox的状态了不是,so。。。
adapter有个getGroupView的方法。有个isExpanded的参数,显示当前的组是收起还是放下,所以ok了
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.item_paramgroup, null);
CheckBox chkGroup = (CheckBox) convertView.findViewById(R.id.chk_group);
chkGroup.setText(getGroup(groupPosition).getParameter_type());
chkGroup.setChecked(isExpanded);
return convertView;
}
对了。几个比较重要的属性
一、去分割线,去自带图标
android:divider="@null" //去掉分割线
android:groupIndicator="@null" //去掉自带的组图标
二、默认展开
//默认展开
for (int i = 0; i < gropBeanLists.size(); i++) {
eplShopCart.expandGroup(i);
}
三、默认只展开一个组(setOnGroupExpandListener监听展开收缩)
eplCarparam.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
for (int i = 0, count = list.size(); i < count; i++) {
if (groupPosition != i) {// 关闭其他分组
eplCarparam.collapseGroup(i);
}
}
}
});
四、总结,万变不离其宗。工作日,die