ExpandableListView无法展开

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值