java - 更改 ExpandableListView 组布局

标签 java android expandablelistview expandablelistadapter

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

我为组 View 创建了自定义布局

<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 不会在点击时展开

最佳答案

您可以使用 View 代替父级行 xml 中的任何按钮或单选按钮,并在运行时设置 View

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

关于java - 更改 ExpandableListView 组布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31724223/

相关文章:

Android ExpandableListView 如何保存展开/折叠状态?

Java - 使用关键字的一部分进行搜索

java - 检测文本变化

beagleboard - 启用根访问

Android:将应用程序添加到 "set picture as"列表

android - 如何在 ExpandableListView 中组合子项及其标题?

java - 单击通知中的按钮时启动 Activity

java - Dozer - 仅当目标对象和源对象具有相同的字段名称时才映射字段

java - UnsupportedOperationException 与 ArrayAdapter.remove

java - 可扩展 ListView setOnChildClickListener 的问题