Question

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.

Was it helpful?

Solution

CheckBoxPreference showContact = (CheckBoxPreference)findPreference("myPreference");
showContact.setChecked(false);

OTHER TIPS

You can call this in your preference activity

    CheckBoxPreference pref = (CheckBoxPreference)findPreference("example_pref_key");
    pref.setChecked(false);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top