简体   繁体   English

复选框显示相同的结果,无论是否选中

[英]Checkbox showing same results regardless of whether it is checked

I have a problem using checkbox in Java. 我在Java中使用复选框时遇到问题。 Regardless of whether the checkbox is checked, the result is always Yes. 无论是否选中该复选框,结果始终为“是”。 Can somebody help me check if there is any error with the code below please? 有人可以帮我检查下面的代码是否有错误?

private String whippedCreamMethod(){
CheckBox checkBoxWhippedCream = (CheckBox) findViewById(R.id.whipped_cream_checkbox);
   if (checkBoxWhippedCream.isSelected()){
       whippedCream = "No";
   } else {
       whippedCream = "Yes";
   }
    return whippedCream;

} }

I think there's a method isChecked() rather than isSelected() ; 我认为有一个方法isChecked()而不是isSelected() ;

final CheckBox checkBox = (CheckBox) findViewById(R.id.checkbox_id);
     if (checkBox.isChecked()) {
         checkBox.setChecked(false);
     }

from https://developer.android.com/reference/android/widget/CheckBox.html 来自https://developer.android.com/reference/android/widget/CheckBox.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM