J'ai un problème avec les préférences dans mon application.
J'ai créé preference.xml :
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<!-- General screen -->
<PreferenceCategory
android:title="@string/general_category"
android:key="prefGeneralCategory">
<CheckBoxPreference
android:icon="@drawable/content_discard"
android:title="@string/pref_general_vibration"
android:defaultValue="false"
android:key="prefVibration"
android:summaryOn="checked"
android:summaryOff="unchecked"
/>
<!-- android:summary="@string/pref_general_vibration_description" -->
<CheckBoxPreference
android:title="@string/pref_general_record_battery"
android:defaultValue="true"
android:summary="@string/pref_general_record_battery_description"
android:key="prefRecordBattery" />
<ListPreference
android:title="@string/pref_network_type"
android:summary="@string/pref_network_type_description"
android:key="prefNetworkType"
android:defaultValue="1"
android:entries="@array/prefNetworkArray"
android:entryValues="@array/prefNetworkValues" />
</PreferenceCategory>
<!-- Network screen -->
<PreferenceCategory
android:title="@string/pref_network_screen"
android:key="prefNetworkCategory">
<PreferenceScreen
android:title="@string/pref_network_screen"
android:key="prefNetworkScreen"
>
<CheckBoxPreference
android:title="@string/pref_network_update"
android:defaultValue="false"
android:summary="@string/pref_network_update_description"
android:key="prefUpdate" />
</PreferenceScreen>
</PreferenceCategory>
</PreferenceScreen>
Mon écran général est correct, mais le deuxième écran (écran réseau) est noir (image ci-dessous).
Le deuxième problème concerne ListPreference. Il me donne une erreur :
04-24 15:20:29.689: E/AndroidRuntime(399): FATAL EXCEPTION: main
04-24 15:20:29.689: E/AndroidRuntime(399): java.lang.NullPointerException
04-24 15:20:29.689: E/AndroidRuntime(399): at android.preference.ListPreference.findIndexOfValue(ListPreference.java:169)
04-24 15:20:29.689: E/AndroidRuntime(399): at android.preference.ListPreference.getValueIndex(ListPreference.java:178)
04-24 15:20:29.689: E/AndroidRuntime(399): at android.preference.ListPreference.onPrepareDialogBuilder(ListPreference.java:190)
04-24 15:20:29.689: E/AndroidRuntime(399): at android.preference.DialogPreference.showDialog(DialogPreference.java:293)
04-24 15:20:29.689: E/AndroidRuntime(399): at android.preference.DialogPreference.onClick(DialogPreference.java:264)
04-24 15:20:29.689: E/AndroidRuntime(399): at android.preference.Preference.performClick(Preference.java:810)
04-24 15:20:29.689: E/AndroidRuntime(399): at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:190)
04-24 15:20:29.689: E/AndroidRuntime(399): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
04-24 15:20:29.689: E/AndroidRuntime(399): at android.widget.ListView.performItemClick(ListView.java:3513)
04-24 15:20:29.689: E/AndroidRuntime(399): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
04-24 15:20:29.689: E/AndroidRuntime(399): at android.os.Handler.handleCallback(Handler.java:587)
04-24 15:20:29.689: E/AndroidRuntime(399): at android.os.Handler.dispatchMessage(Handler.java:92)
04-24 15:20:29.689: E/AndroidRuntime(399): at android.os.Looper.loop(Looper.java:123)
04-24 15:20:29.689: E/AndroidRuntime(399): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-24 15:20:29.689: E/AndroidRuntime(399): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 15:20:29.689: E/AndroidRuntime(399): at java.lang.reflect.Method.invoke(Method.java:507)
04-24 15:20:29.689: E/AndroidRuntime(399): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-24 15:20:29.689: E/AndroidRuntime(399): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-24 15:20:29.689: E/AndroidRuntime(399): at dalvik.system.NativeStart.main(Native Method)
Ce sont mes autres fichiers :
<resources>
...
<string name="general_category">Obecné</string>
<string name="pref_general_vibration">Povolit vibrace</string>
<string name="pref_general_record_battery">Kontrola baterie</string>
<string name="pref_general_record_battery_description">vypnout nahrávání, pokud je baterie pod 20%</string>
<string name="pref_network_screen">Sítové nastavení</string>
<string name="pref_network_type">Volba síte</string>
<string name="pref_network_type_description">Vyberte typ pripojení</string>
<string name="pref_network_update">Automatické aktualizace</string>
<string name="pref_network_update_description">Povolení k automatické aktualizace aplikace</string>
<string-array name="prefNetworkArray">
<item name="net1">wifi (default)</item>
<item name="net2">3G</item>
<item name="net3">wifi/3G</item>
</string-array>
<integer-array name="prefNetworkValues">
<item name="net1">1</item>
<item name="net2">2</item>
<item name="net3">3</item>
</integer-array>
...
</resources>
Dans PreferenceActivity, je n'ai que :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.preferences); }
Pouvez-vous m'aider, s'il vous plaît ?