java - RadioGroup ,再次单击相同的元素不起作用
问题描述
我试图在这个演示示例中使用 RadioGroup
<RadioGroup
android:id="@+id/hello_world"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:ignore="MissingConstraints">
<RadioButton
android:id="@+id/checkbox_meat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
tools:ignore="OnClick" />
<RadioButton
android:id="@+id/checkbox_cheese"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</RadioGroup>
<Button
android:id="@+id/button1"
android:layout_width="100dp"
android:layout_height="50dp"
android:text="button1" />
和这样的Java代码:
firstCB.setText(firstCheckArray[i]);
secondCB.setText(secondCheckArray[i]);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (i<newStringArray.length-1){
i++;
firstCB.setText(firstCheckArray[i]);
secondCB.setText(secondCheckArray[i]);
}
}
});
我面临的问题是当我增加(1)并且下一个单词组来时,如果我想选择相同的单选按钮,直到我选择另一个单选按钮才选择它,那么我可以选择相同的旧单选按钮(换句话说,如果我选择第一个选择,在下一步中,第一个选择不可选择,直到我选择另一个,然后我可以回到第一个选择
解决方案
You can set Radio button check by code in button1 click, like this
radioButton.setChecked(true);
And in your layout add
android:checked="true"
It will check when show
<RadioButton
android:id="@+id/checkbox_meat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:checked="true"
tools:ignore="OnClick" />
推荐阅读
- jquery - 从多个类中获取结构化文本
- java - 如何在每秒钟服务器启动时修复“javax.xml.parsers.FactoryConfigurationError”
- php - 在 google pagespeed curl request-PHP 中获取总分
- r - 如何逐句循环遍历txt文件?
- android - 如何实现从回收器视图中删除元素的动画
- r - 如何在 R 中绘制或可视化多变量 D-vine copula
- ios - 只有 UNLocationNotificationTrigger 没有被触发
- python - 问答+NLP中的问题生成
- django - Django 的“精确”字段查找是否执行不区分大小写的搜索?
- python - 如何从文件中获取元素并将它们读入python中的列表