Android listpreferences,如何保存个人偏好
我有一些列表首选项,但我不知道如何保存列表中的各个值。我该怎么做?这是我的
http://i41.tinypic.com/dh4gvo.png
Preference customPref = (Preference) findPreference("notificationPref");
customPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
SharedPreferences customSharedPreference = getSharedPreferences(
"notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = customSharedPreference
.edit();
editor.putString("notification",
"The preference has been clicked");
editor.commit();
return true;
}
});
我的列表单击侦听器仅适用于列表首选项页面中的主项目,而不适用于弹出窗口本身中的项目。如何保存在弹出窗口中选择的选项?
I have some list preferences, but I don't know how to save the individual values from the list. How do I do it? Here is what I have
http://i41.tinypic.com/dh4gvo.png
Preference customPref = (Preference) findPreference("notificationPref");
customPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
SharedPreferences customSharedPreference = getSharedPreferences(
"notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = customSharedPreference
.edit();
editor.putString("notification",
"The preference has been clicked");
editor.commit();
return true;
}
});
my list click listener is only for the main item in the list preferences page, but not the items in the popup itself. How do I save the choice selected in the popup itself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这通常是自动的。在您的首选项屏幕 XML 中,您应该有如下内容:
在您的 strings.xml 中:
“Values”数组指定保存在首选项中的(字符串)值,而“Entries”数组指定显示到屏幕的项目的文本。用户。每次用户选择一个项目时,“Values”数组中的相应值都会保存到指定键(本例中为“PreferenceKey”)下的首选项中。
This is usually automatic. In your preference screen XML, you should have something like this:
And in your strings.xml:
The "Values" array specify the (string) value saved in preferences, whereas the "Entries" array specify the text of the items displayed to the user. Each time the user select an item, its corresponding value in the "Values" array is saved to preferences under the specified key ("PreferenceKey" in this example).
您可以这样阅读偏好设置...
You can read preferences like this...