我有ExpandableListview
如下,
但是当我在父行中使用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;
}
}
答案 0 :(得分:0)
尝试在布局row_parent
中设置CheckBoxandroid:focusable="false"
答案 1 :(得分:0)
在XML文件中尝试复选框clickable false。将此行添加到您的复选框。
android:clickable="false"