在我的代码中,我使用了 Preference.setSummary()
方法将设置的摘要行更改为某个字符串。在我的主要 Activity 中,当我需要检索此设置的值时,我调用了 SharedPreferences
对象的 getString(key)
方法,其中 key
是EditTextPreference
的键。
现在我真的想知道 setSummary
是否也通过相同的键将 SharedPreferences
中的首选项值设置为我传递给 setSummary
的值>,因为我真的从未创建过 SharedPreferences.Editor
对象并显式调用了 putString
方法。
除了以下内容外,文档没有说明任何具体内容:
Sets the summary for this Preference with a CharSequence.
Parameters
summary The summary for the preference.
最佳答案
首先,我很抱歉我问了这个问题,尽管类(class)中的下一个讲座(由 Google 提供)提供了答案,但我认为这是值得的,因为在 SO 上没有关于 Preference 的问题.setSummary()
还将值保存在 SharedPreferences
中。
答案是,当 summary 发生变化时,SharedPreferences
中的值 也会发生变化,如 this video 中引用的那样Google 官方 Android 类(class):
When the user selects an option, it's saved into SharedPreferences.
提供一些上下文,“用户选择一个选项”是指在 ListPreference
中选择一个选项,然后将其设置为其摘要。
关于android - Preference.setSummary() 有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30001435/