Java CheckBox.setChecked()不起作用

Java CheckBox.setChecked()不起作用,java,android,checkbox,Java,Android,Checkbox,因此,这根本不起作用 CheckBox chck_bluetooth = (CheckBox) findViewById(R.id.chck_bluetooth); if (mProperties.getProperty("bluetooth") == "true") { chck_bluetooth.setChecked(true); Log.i("Properties", "bluetooth = " + mProperties.getProperty("bluetooth"

因此,这根本不起作用

CheckBox chck_bluetooth = (CheckBox) findViewById(R.id.chck_bluetooth);
if (mProperties.getProperty("bluetooth") == "true") {
    chck_bluetooth.setChecked(true);
    Log.i("Properties", "bluetooth = " + mProperties.getProperty("bluetooth"));
} else {
    chck_bluetooth.setChecked(false);
    Log.i("Properties", "bluetooth = " + mProperties.getProperty("bluetooth"));
}

嗯,日志告诉我bluetooth被设置为“true”,所以我想复选框一定有问题。

如果属性值是字符串,则需要使用
equals()
进行比较:

if (mProperties.getProperty("bluetooth").equals("true")) {

不,日志告诉您,
mproperty.getProperties(“蓝牙”)
true
,而不是代码通过了“true”路径(第一条路径)。登录时,请确保两种情况下的登录内容都不相同,否则,您如何知道采用了哪条路径?!区别在于“蓝牙”的价值。它可以是“真的”,也可以是“假的”。这两个值都是在properties文件中设置的当然,我并没有指出,我的意思是您编写的内容相当于
if(“true”){doA();}else{doB();}Log.I(…)
。所以说“日志告诉我bluetooth被设置为“true”,并不能真正告诉我们checkbox.setChecked(true)实际上被调用了。“你明白我现在的意思了吗?