我是Android的新手请让我知道我做错了什么,我添加了一个无线电组,然后添加了Gridlayout以2x2形式的矩阵对齐单选按钮,它对齐好,但问题是它不是选择任何单选按钮时取消选择以前选择的选项。我怎样才能做到这一点?
All radio buttons are getting selected. None of them are deselecting upon changing selection of radio button. Please suggest me any approach.
Thanks
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton"
android:id="@+id/radOption1"
android:layout_row="0"
android:layout_column="0"
android:padding="5dp" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton"
android:id="@+id/radOption2"
android:layout_row="0"
android:layout_column="1"
android:padding="5dp" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton"
android:id="@+id/radOption3"
android:layout_row="1"
android:layout_column="0"
android:padding="5dp" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton"
android:id="@+id/radOption4"
android:layout_row="1"
android:layout_column="1"
android:padding="5dp" />
</GridLayout>
</RadioGroup>
答案 0 :(得分:1)
RadioGroup
基本上是LinearLayout
,您可以在RadioButtons
内调整layout
。它不像通用GridLayout
那样可以存储任何内容(在您的示例中为RadioButtons
),它将处理您将在层次结构中放置的任何RadioGroup
。
TLDR:RadioButtons
可让您水平或垂直对齐LinearLayout
- var x;
function filterName(n) {
x = document.getElementsByClassName(n);
console.log(x.length);
for (i = 0; i < x.length; i++) {
x[i].setAttribute("class", "hidden");
}
}
。
您需要做的事情在此question中进行了描述。