Hello I need to know how to set a value programmatically.
I am using that code
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
.
.
.
SharedPreferences.Editor geted = prefs.edit();
geted.putBoolean("checkBox_Schedule", false);
geted.commit();
But I dont see anything change
The code of my xml for my checkboxPreference is
<CheckBoxPreference
android:defaultValue="false"
android:dependency="checkBox"
android:key="checkBox_Schedule"
android:summary="On/Off"
android:title="Schedule" />
One solution is to do
startActivity(new Intent(SetPreference.this, SetPreference.class));
But this is not what I want to do.
CheckBoxPreference showContact = (CheckBoxPreference)findPreference("myPreference");
showContact.setChecked(false);
You can call this in your preference activity
CheckBoxPreference pref = (CheckBoxPreference)findPreference("example_pref_key");
pref.setChecked(false);
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