I am trying to set up the default value for the list preferences in my app, but I am having trouble with the default value, as when I try to run the app the default values that I chose in both list preferences are not being selected in runtime. This is my xml code:
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory app:title="@string/display_header">
<ListPreference
app:key="language"
android:title="@string/language_title"
app:summary="@string/en"
android:entries="@array/lang_entries"
android:entryValues="@array/lang_values"
android:defaultValue="@string/en"
/>
<ListPreference
app:key="display"
app:title="@string/display_mode_title"
app:entries="@array/display_entries"
app:entryValues="@array/display_values"
app:summary="@string/automatic"
android:defaultValue="@string/automatic"/>
</PreferenceCategory>
</PreferenceScreen>
I tried uninstalling and reinstalling the app but it did not work. I also checked that the string names that I used in the default value are correct, and I also made sure that the default value matches the one in the string array of entries. Please help me fix this problem
I just found out that I had to replace the android:defaultValue
line by app:defaultValue
and I had to pass the corresponding value to the entry that would be the default value in runtime.