【发布时间】:2015-10-11 00:49:24
【问题描述】:
我正在尝试使用其中有 2 个单选按钮的单选组。我想为每个单选按钮设置一个值,例如该值是男性和女性。之后,当我已经点击了我的单选按钮时,它将显示选择的值。你怎么能做到这一点?感谢您的帮助。
我尝试过这样的事情只是为了测试我将如何设置一个值
public void onRadioButtonClicked(View radioButton) {
int count = radioGroup.getChildCount();
for (int i = 0; i < count; i++) {
View o = radioGroup.getChildAt(i);
if (o instanceof RadioButton) {
RadioButton radioBtn = (RadioButton)o;
// get the state
boolean isChecked = radioBtn.isChecked();
// to set the check
radioBtn.setChecked(true);
}
}
}
但我认为这不是我想要的。
我已经尝试过radioGroup.setId(),假设单选按钮已经有值,但它只是显示无意义的数字。
【问题讨论】:
-
如果您还没有尝试过任何事情,建议您这样做。可能有帮助的东西:OnCheckedChangeListener
-
我已经更新了我的问题@Karakuri
标签: android radio-button radio-group