更改 ExpandableListView 组布局

Change ExpandableListView group layout

我想创建具有自定义组布局的 ExpandableListView,其中包含一个 RadioButton、一个 EditText 和一个 Button。 设计如下:

我为群组视图创建了自定义布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp" >

<RadioButton
    android:id="@+id/rbGroup"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<EditText
    android:id="@+id/etGroup"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@android:color/transparent"
    android:ems="10"
    android:focusable="false" />

<Button
    android:id="@+id/btnEditGroupName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/edit" />
</LinearLayout>

我在适配器中使用了这个布局

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
                View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.item_groups, parent, false);
    }

    final int ind = groupPosition;

    CustomGroup group = (CustomGroup) getGroup(groupPosition);
    EditText etGroup = (EditText) convertView.findViewById(R.id.etGroup);
    etGroup.setText(group.getName());

    ((CheckedTextView) convertView).setChecked(isExpanded);

    RadioButton rbGroup = (RadioButton) convertView.findViewById(R.id.rbGroup);
    rbGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                selectedGroup = ind; 
            }
        }
    });

    return convertView;
}

但在这种情况下,ExpandableListView 不会在点击时展开

您可以在父项的 xml 行中获取视图而不是任何按钮或单选按钮,并在 运行 时间设置视图

或者您可以通过示例替换视图 here