【发布时间】:2010-05-20 13:45:26
【问题描述】:
我的问题是,当我启动应用程序时,用户没有打开我的PreferenceActivity,所以当我检索它们时,我的preference.xml 文件中没有定义任何默认值。
preference.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:key="applicationPreference" android:title="@string/config"
>
<ListPreference
android:key="pref1"
android:defaultValue="default"
android:title="Title"
android:summary="Summary"
android:entries="@array/entry_names"
android:entryValues="@array/entry_values"
android:dialogTitle="@string/dialog_title"
/>
</PreferenceScreen>
来自我的主要活动的片段(onCreate 方法):
SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(this);
String pref1 = appPreferences.getString("pref1", null);
结果我得到一个null 值。
【问题讨论】:
标签: android xml android-preferences