如何在 PreferenceActivity 第一次启动时显示 defaultValues?
我已在 xml 文件、preferences.xml 中定义了我的首选项。我还有一个扩展 PreferenceActivity 的 SettingsWindow 类。我已在 xml 文件中的首选项中设置了 android:defaultValue 属性,但它们在应用程序首次启动时不会出现。如何在第一次启动 Activity 时将 xml 文件中定义的默认值加载到 SettingsWindow 中?
I've defined my preferences in an xml file, preferences.xml. I've also got a SettingsWindow class which extends PreferenceActivity. I've set the android:defaultValue attribute on my preferences in the xml file but they don't appear the first time the app is launched. How do I load the default values defined in the xml file into the SettingsWindow the first time the activity is launched?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
弄清楚发生了什么事。我已经定义了偏好设置.xml 文件和关联的
PreferenceActivity
,但没有指定默认值,并在模拟器中运行它。后来,我将defaultValue
标记添加到 xml 文件中。当我部署到模拟器时,这不是第一次加载首选项,因此跳过了defaultValue
。删除应用程序的数据并卸载\重新安装应用程序解决了该问题。Figured out what's going on. I had defined my preferences.xml file and associated
PreferenceActivity
without specifying defaults and ran that in the emulator. Later on, I added thedefaultValue
tags to the xml file. When I deployed to the emulator, it wasn't the first time the preferences had been loaded so thedefaultValue
s were skipped. Deleting the app's data and uninstalling\reinstalling the app fixed the issue.