【问题标题】:Checkbox showing same results regardless of whether it is checked复选框无论是否选中都显示相同的结果
【发布时间】:2017-10-09 20:56:45
【问题描述】:

我在 Java 中使用复选框时遇到问题。无论复选框是否被选中,结果始终为是。有人可以帮我检查一下下面的代码是否有任何错误吗?

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

}

【问题讨论】:

标签: java checkbox


【解决方案1】:

我认为有一种方法isChecked() 而不是isSelected()

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

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

【讨论】:

  • 能否将其标记为您正在寻找的答案?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-27
  • 2012-02-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多