Sergey Maslenyuk
Sergey Maslenyuk

Reputation: 103

How to add new value to listpreference and save it?

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?

Upvotes: 0

Views: 2183

Answers (1)

Egor
Egor

Reputation: 40193

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());

Upvotes: 1

Related Questions