Question

I have a list Preference that created from resource xml. I added preference that created dialog in which user can add value to listPreference.

using those methods i added new value:

  entries = getEntries();
  entryValues = getEntryValues();

when user is adding values to listpreference, its displayed. But when preferenceScreen is recreating new value disappearing.

How can i save those new values?

Was it helpful?

Solution

Problem is that when you're reopening your PreferenceScreen, it loads the ListPreference's values from XML. You can change this behavior using the setEntries() and setEntryVaues() methods of ListPreference. Of course you need to somehow store all the values and their indexes that your users enter. You can use databases or SharedPreferences for it. Hope this helps.

EDIT

Saving the value of a ListPreference into the SharedPreferences:

preferences.edit().putString(listPreference.getKey(), listPreference.getValue());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top