Mano Mano - 2 months ago 9
Android Question

Set Value of a CheckBoxPreference in an Activity

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.

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