gpt4 book ai didi

java - 更改 ExpandableListView 组布局

转载 作者:行者123 更新时间:2023-12-01 11:16:48 25 4
gpt4 key购买 nike

我想创建具有自定义组布局的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com