【问题标题】:RadioGroup Visibility Issue at Runtime运行时 RadioGroup 可见性问题
【发布时间】: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


【解决方案1】:

试试这个,可能会有帮助

    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 { 
    if ("some condition 1") {showAlert("Some Message 1");}
 else {showAlert("Some Message 2");}
}

祝你好运

【讨论】:

  • 我必须满足所有这些条件以及 RadioGroup 可见性的条件
  • 能否解释一下,是否需要其他可见性状态条件?
猜你喜欢
  • 2012-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-21
  • 2021-05-27
  • 1970-01-01
相关资源
最近更新 更多