简体   繁体   中英

CheckBox.setChecked() is not working

So, this is simply not working.

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"));
}

Well, the log told me that bluetooth were set to "true", so I guess there must be a problem with the checkbox.

If the property value is a string, you need to use equals() to compare it:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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