sharedpreferences - Android no set default values -
i followed the instructions setting default preference values step step not work.
1º set default values:
<preferencecategory android:title="@string/settings_game" > <listpreference android:defaultvalue="1.5" android:entries="@array/intervale_count" android:entryvalues="@array/intervale_count_values" android:key="interval" android:title="@string/interval" /> <listpreference android:defaultvalue="@string/mode_normal" android:entries="@array/mode_game" android:entryvalues="@array/mode_game_values" android:key="mode" android:title="@string/mode" /> </preferencecategory> <preferencecategory android:title="@string/settings_sound" > <listpreference android:defaultvalue="@string/stone" android:entries="@array/time_sounds" android:entryvalues="@array/time_sounds_values" android:key="time_sounds" android:title="@string/sounds_stones" /> <listpreference android:defaultvalue="@string/vuvucela" android:entries="@array/gong_sounds" android:entryvalues="@array/gong_sounds_values" android:key="gong_sounds" android:title="@string/sounds_gong" /> </preferencecategory>
2º preferences in mainactivity
:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); preferencemanager.setdefaultvalues(this, r.xml.preferences, false); sp = preferencemanager.getdefaultsharedpreferences(getbasecontext()); }
but when open preference view no preferences selected, strings of declare in android:defaultvalue
same 1 of options ihave in array of data in android:entries
.
note: try change true
boolean in
preferencemanager.setdefaultvalues(this, r.xml.preferences, false);
but still not work.
i've tried uninstall , delete data of app still not work.
edit: array values
<string-array name="intervale_count"> <item>1</item> <item>1.3</item> <item>1.5</item> <item>1.7</item> <item>2</item> </string-array> <string-array name="intervale_count_values"> <item>1000</item> <item>1300</item> <item>1500</item> <item>1700</item> <item>2000</item> </string-array> <string-array name="mode_game"> <item>@string/mode_normal</item> <item>@string/mode_extension</item> <item>@string/mode_infinite</item> </string-array> <string-array name="mode_game_values"> <item>100</item> <item>50</item> <item>1000</item> </string-array> <string-array name="time_sounds"> <item>@string/alan</item> <item>@string/cash_reg</item> <item>@string/censure</item> <item>@string/crow</item> <item>@string/doh</item> <item>@string/fb_noti</item> <item>@string/achievement</item> <item>@string/metal_gear</item> <item>@string/duck</item> <item>@string/pan</item> <item>@string/drum</item> <item>@string/stone</item> </string-array> <string-array name="time_sounds_values"> <item>2131099648</item> <!-- alan --> <item>2131099649</item> <!-- registradora --> <item>2131099650</item> <!-- censura --> <item>2131099651</item> <!-- cuervo --> <item>2131099652</item> <!-- doh --> <item>2131099653</item> <!-- fb --> <item>2131099655</item> <!-- logro --> <item>2131099656</item> <!--metal gear --> <item>2131099657</item> <!-- pato --> <item>2131099658</item><!-- sarten --> <item>2131099660</item> <!-- tambor --> <item>2131099659</item><!-- stone --> </string-array> <string-array name="gong_sounds"> <item>@string/gong</item> <item>@string/vuvucela</item> </string-array> <string-array name="gong_sounds_values"> <item>2131099654</item> <!-- gong --> <item>2131099661</item> <!-- vuvucela --> </string-array>
the defaultvalue
attribute listpreference
needs value, not entry text. in other words, should element in array pass android:entryvalues
, not element in array pass android:entries
.
for example, gong sounds preference should use android:defaultvalue="2131099661"
instead of android:defaultvalue="@string/vuvucela"
Comments
Post a Comment