【发布时间】:2016-07-13 11:30:49
【问题描述】:
我围绕 RadioGroup 的 Visibility 写了一个小逻辑,但是尝试时失败了:
if ("some condition") {
showAlert("Some Message");
} else if ("some condition") {
showAlert("Some Message");
} else if(radioGroup.getVisibility() == View.VISIBLE) {
if (radioGroup.getCheckedRadioButtonId() == -1) {
Toast.makeText(getApplicationContext(), "Please make a selection", Toast.LENGTH_SHORT).show();
return;
}
} else {
saveData();
finish();
}
也试过这个:
if ("some condition") {
showAlert("Some Message");
} else if ("some condition") {
showAlert("Some Message");
} else {
if(radioGroup.getVisibility() == View.VISIBLE) {
if (radioGroup.getCheckedRadioButtonId() == -1) {
Toast.makeText(getApplicationContext(), "Please make a selection", Toast.LENGTH_SHORT).show();
return;
}
else {
saveData();
finish();
}
}
else {
saveData();
finish();
}
}
我在上面尝试过的,
如果 Radio Group 是 Visible 并且在上面的代码中没有选择任何单选按钮,我只是想显示 Toast“请进行选择”,但我收到此消息“请进行选择” selection" 甚至 RadioGroup 在 Activity 中是 not visible。
我在哪里犯了错误?为什么即使 RadioGroup 在 Activity 中不可见,我也会收到“请进行选择”消息?
【问题讨论】:
-
检查 radiogroup.isShown() 而不是 getVisiblit()
标签: java android if-statement android-activity android-radiogroup