How to add new value to listpreference and save it?

天大地大妈咪最大 提交于 2020-01-06 19:28:37

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/11429796/how-to-add-new-value-to-listpreference-and-save-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!