Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在首次启动PreferenceActivity时显示默认值?_Android_Preferences_Android Preferences_Preferenceactivity - Fatal编程技术网

Android 如何在首次启动PreferenceActivity时显示默认值?

Android 如何在首次启动PreferenceActivity时显示默认值?,android,preferences,android-preferences,preferenceactivity,Android,Preferences,Android Preferences,Preferenceactivity,我已经在一个xml文件preferences.xml中定义了我的首选项。我还有一个SettingsWindow类,它扩展了PreferenceActivity。我已经在xml文件中的首选项上设置了android:defaultValue属性,但它们在应用程序第一次启动时不会出现。如何在第一次启动活动时将xml文件中定义的默认值加载到设置窗口中?了解发生了什么。我已经定义了我的preferences.xml文件和关联的PreferenceActivity,但没有指定默认值,并在emulator中运

我已经在一个xml文件preferences.xml中定义了我的首选项。我还有一个SettingsWindow类,它扩展了PreferenceActivity。我已经在xml文件中的首选项上设置了android:defaultValue属性,但它们在应用程序第一次启动时不会出现。如何在第一次启动活动时将xml文件中定义的默认值加载到设置窗口中?

了解发生了什么。我已经定义了我的preferences.xml文件和关联的
PreferenceActivity
,但没有指定默认值,并在emulator中运行了它。后来,我将
defaultValue
标记添加到xml文件中。当我部署到模拟器时,这不是第一次加载首选项,因此跳过了
defaultValue
s。删除应用程序的数据并卸载\重新安装应用程序修复了问题。

了解了发生的情况。我已经定义了我的preferences.xml文件和关联的
PreferenceActivity
,但没有指定默认值,并在emulator中运行了它。后来,我将
defaultValue
标记添加到xml文件中。当我部署到模拟器时,这不是第一次加载首选项,因此跳过了
defaultValue
s。删除应用程序的数据并卸载\重新安装应用程序解决了问题。

给我们一点代码,让我们看看发生了什么。给我们一点代码,让我们看看发生了什么。