androidmysqlandroid-studiosharedpreferencesandroid-multiselectlistpreference

SharedPreference.Editor with multiSelectListPreference


So I have a multiSelectListPreference and i want use SharedPreference.Editor to change the values of the multiSelectListPreference in my database when the user changes his preference. For that i use the putBoolean function for each option. However i don't know what i should use as the first argument (where the question mark is).

In the android docs they say that the first argument should be the name of the preference to modify. The android:key of the multiSelectListPreference is "options_list". How do i get the key of each individual option in my multiSelectListPreference?

private SharedPreferences.Editor spPreferencesEditor;

spPreferencesEditor.putBoolean("?", preferences.getBooleanOfOption1());
spPreferencesEditor.putBoolean("?", preferences.getBooleanOfOption2());
spPreferencesEditor.putBoolean("?", preferences.getBooleanOfOption3());


Solution

  • You should put a defult name there, every name you like. What is important is that names for different share preferences should be diffirent and this way they will be recognized. For example you may have:

        spPreferencesEditor.putBoolean("1", preferences.getBooleanOfOption1());
     spPreferencesEditor.putBoolean("2", preferences.getBooleanOfOption2());
     spPreferencesEditor.putBoolean("3", preferences.getBooleanOfOption3());