当应用程序第一次启动时,我想通过使用’android:defaultValue’属性存储我在prefences.xml中定义的所有默认值,但其中一些不存储在设备上 – 有人可以告诉我为什么?
<?xml version="1.0" enCoding="utf-8"?>
<Preferencecategory androID:title="@string/prefs_cat_Title_x"> <ListPreference androID:key="@string/prefs_key_1" androID:title="@string/prefs_Title_1" androID:summary="@string/prefs_summary_1" androID:entrIEs="@array/array1" androID:entryValues="@array/array1" androID:defaultValue="@string/prefs_default_1"/> <com.myapp.TimePreference androID:key="@string/prefs_key_2" androID:title="@string/prefs_Title_2" androID:defaultValue="@string/prefs_default_2" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content"/> <com.myapp.TimePreference androID:key="@string/prefs_key_3" androID:title="@string/prefs_Title_3" androID:defaultValue="@string/prefs_default_3" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content"/> <ListPreference androID:key="@string/prefs_key_4" androID:title="@string/prefs_Title_4" androID:summary="@string/prefs_summary_4" androID:entrIEs="@array/array2" androID:entryValues="@array/array2" androID:defaultValue="@string/prefs_default_4"/> <CheckBoxPreference androID:key="@string/prefs_key_5" androID:title="@string/prefs_Title_5" androID:summary="@string/prefs_summary_5" androID:defaultValue="false"/> <CheckBoxPreference androID:key="@string/prefs_key_6" androID:title="@string/prefs_Title_6" androID:summary="@string/prefs_summary_6" androID:defaultValue="false"/></Preferencecategory><Preferencecategory androID:title="@string/prefs_cat_Title_common"> <com.myapp.DatabaseresetPreference androID:title="@string/prefs_Title_7" androID:summary="@string/prefs_summary_7" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content"/></Preferencecategory>
解决方法:
根据com.myapp.TimePreference的超类的不同,您可能必须在onSetinitialValue()中自己保留默认值.
EditTextPreference已实现此功能,但DialogPrefercence或Preference只有一个空实现.
protected voID onSetinitialValue(boolean restoreValue, Object defaultValue) { persistString(restoreValue ? getPersistedString((String)defaultValue) : (String)defaultValue));}
总结 以上是内存溢出为你收集整理的android – 来自xml首选项文件的defaultValue没有存储 – 为什么?全部内容,希望文章能够帮你解决android – 来自xml首选项文件的defaultValue没有存储 – 为什么?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)