ExpandableListview可以在父行中包含CheckBox吗?

时间:2018-01-25 10:30:54

标签: android expandablelistview

我有ExpandableListview如下,

enter image description here

但是当我在父行中使用CheckBox 时。我无法在父母中执行点击。在getChildView构建时,系统会自动Adapter跳过。

删除CheckBox(来自父级)后一切正常。

这是我的ExpandableListAdapter,

public class ExpandableListAdapter extends BaseExpandableListAdapter {

        @Override
        public Object[] getChild(int groupPosition, int childPosititon) {
            return listChild.get(listParent.get(groupPosition)[0])
                    .get(childPosititon);
        }

        @Override
        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        }

        @Override
        public View getChildView(int groupPosition, final int childPosition,
                                 boolean isLastChild, View convertView, ViewGroup parent) {

            if (convertView == null) {
                LayoutInflater infalInflater = (LayoutInflater) context
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = infalInflater.inflate(R.layout.row_child, null);
            }

            TextView tv_chapName = convertView.findViewById(R.id.tv_chapName);
            TextView tv_apkSize = convertView.findViewById(R.id.tv_apkSize);
            TextView tv_installedApkSize = convertView.findViewById(R.id.tv_installedApkSize);

            final Object[] itemArray = getChild(groupPosition, childPosition);

            if (itemArray != null && itemArray.length > 0) {
                tv_chapName.setText(itemArray[0] + "");
                tv_apkSize.setText(itemArray[1] + "");
                tv_installedApkSize.setText(itemArray[2] + "");
            }
            return convertView;
        }

        @Override
        public int getChildrenCount(int groupPosition) {
            return listChild.get(listParent.get(groupPosition)[0])
                    .size();
        }

        @Override
        public Object[] getGroup(int groupPosition) {
            return listParent.get(groupPosition);
        }

        @Override
        public int getGroupCount() {
            return listParent.size();
        }

        @Override
        public long getGroupId(int groupPosition) {
            return groupPosition;
        }

        @Override
        public View getGroupView(int groupPosition, boolean isExpanded,
                                 View convertView, ViewGroup parent) {
            if (convertView == null) {
                LayoutInflater infalInflater = (LayoutInflater) context
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = infalInflater.inflate(R.layout.row_parent, null);
            }

            Object[] parentArray = getGroup(groupPosition);

            TextView tv_chapName = convertView.findViewById(R.id.tv_chapName);
            TextView tv_apkSize = convertView.findViewById(R.id.tv_apkSize);
            TextView tv_installedApkSize = convertView.findViewById(R.id.tv_installedApkSize);
            ImageView iv_icon = convertView.findViewById(R.id.iv_icon);
            iv_icon.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                }
            });
//            CheckBox cb_parent = convertView.findViewById(R.id.cb_parent);
//            cb_parent.setOnCheckedChangeListener(null);

            if (parentArray != null && parentArray.length > 0) {
                tv_chapName.setText(parentArray[0] + "");
                tv_apkSize.setText(parentArray[1] + "");
                tv_installedApkSize.setText(parentArray[2] + "");
            }
            return convertView;
        }

        @Override
        public boolean hasStableIds() {
            return false;
        }

        @Override
        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return true;
        }
    }

2 个答案:

答案 0 :(得分:0)

尝试在布局row_parent

中设置CheckBox android:focusable="false"

答案 1 :(得分:0)

在XML文件中尝试复选框clickable false。将此行添加到您的复选框。

android:clickable="false"