简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM