What I am trying to do is checking the SharedPreferences
if the volume and vibration is on
or off
.
If it is on the ToggleButton
should be set to on
, else, off
.
I already tried using setChecked()
and setSelected()
on ToggleButton
s but it didn't change the TogggleButton
s' state.
I also tried initializing a variable for the true
and false
just to make sure but still doesn't work.
What seems to be the problem?
optionsDB = getSharedPreferences(table, 0);
String volReturned = optionsDB.getString("volume", "Couldn't load data");
String vibReturned = optionsDB.getString("vibration", "Couldn't load data");
Toast.makeText(this, "Vol: "+volReturned+" Vib: "+ vibReturned, Toast.LENGTH_LONG).show();
boolean boolT = true;
boolean boolF = false;
if (volReturned=="On"){
/*tbtnvol.setChecked(true);*/
tbtnvol.setSelected(boolT);
}else{
tbtnvol.setSelected(boolF);
}
if (vibReturned=="On"){
tbtnvib.setSelected(boolT);
}else{
tbtnvib.setSelected(boolF);
}
Well, there are two methods associated with ToggleView:
setChecked(Boolean value)
setSelected(Boolean value)
And both of them are to be used in pair. If you want to set toggle view selected, pass "true" to both these methods and vice-versa.
The reason being, setChecked() sets the intrinsic boolean dataMember associated with your view object and setSelected sets the UI associated with your view object.
Yes, this is wired and actually one method should set both UI and data, but this is how it was implemented and thus this is how we must use these methods-in pair.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With