【发布时间】:2016-02-06 06:56:42
【问题描述】:
我正在尝试用可扩展的列表视图做这样的事情:
PARENT 1:
- child 1 ( Radio Button)
- child 2 ( Radio Button)
- child 3 (Radio Button)
- child 4 (Checkbox)
- child 5 (Checkbox)
PARENT 2 ...
但是:child 1,child2,child3 应该像一个无线电组。因此,例如,如果我选中 child2,child1 和 child3 应该被取消选中。
我已经设法做到这一点:一些孩子有单选按钮,一些有复选框。但单选按钮不相互连接,也不像单选组。
谁能帮我解决这个问题?
我的 XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:focusable="false"
>
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/checkbox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:clickable="false"
android:layout_column="0"
android:layout_row="0" />
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingRight="?android:attr/listPreferredItemPaddingRight"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:focusable="false"
android:layout_column="2"
android:layout_row="0" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/text2"
android:layout_row="1"
android:focusable="false"
android:layout_column="2" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton"
android:layout_row="0"
android:layout_column="0"
android:focusable="false"
android:clickable="false"/>
</GridLayout>
【问题讨论】:
-
如果您的单选按钮未分组,则使用单选按钮没有意义。也许,如果您能进一步解释您想要达到的目标,那么我们可能会提供进一步的建议。
-
好的。我的应用程序是服务计算。并且消费者选择一些服务(他/她应该检查复选框)并且应用程序计算整个总和。但是有些服务是可选的——我可以选择这个或另一个。这就是为什么我需要像广播组一样的单选按钮。
标签: android checkbox radio-button expandablelistview