Value CheckBoxPreference in action

Hello, I need to know how to set a value programmatically.

I am using this code

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); . . . SharedPreferences.Editor geted = prefs.edit(); geted.putBoolean("checkBox_Schedule", false); geted.commit(); 

But I don't see anything change

My xml code for my checkboxPreference

  <CheckBoxPreference android:defaultValue="false" android:dependency="checkBox" android:key="checkBox_Schedule" android:summary="On/Off" android:title="Schedule" /> 

One solution is

  startActivity(new Intent(SetPreference.this, SetPreference.class)); 

But that is not what I want to do.

+6
source share
2 answers
 CheckBoxPreference showContact = (CheckBoxPreference)findPreference("myPreference"); showContact.setChecked(false); 
+13
source

You can trigger this in your activity preferences.

  CheckBoxPreference pref = (CheckBoxPreference)findPreference("example_pref_key"); pref.setChecked(false); 
+2
source

Source: https://habr.com/ru/post/925406/


All Articles