Search code examples
androidlayoutandroid-preferences

how to display preference values


I'm trying to migrate the preferences part of my app because of warning

default constructor in android.preference.preferenceactivity is deprecated

But, even after reading a lot of ressources, I don't understand why I can't have 2 preference values (string and integer) displayed in front of (or below) the EditTextPreference as I had before.

  • "Compte" (in the capture) (String) is enabled="false" because I don't want the user can edit it. But I want the user can see the account name in preferences.
  • "Nom de jours" (Integer) can be edited, if the user click on it, but I want the value is shown without opening editing mode.

prefs.xml:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceCategory app:title="@string/prefsCatGlobalTitle">
    <EditTextPreference
        app:enabled="false"
        app:key="param_email"
        app:title="@string/cnxEmailLabel" />
    </PreferenceCategory>
    <PreferenceCategory app:title="@string/prefsCatAlertsTitle">
        <EditTextPreference
            app:defaultValue="7"
            android:inputType="number"
            app:key="prefsAlertNbDays"
            android:maxLength="2"
            app:maxLines="1"
            android:selectAllOnFocus="true"
            app:singleLine="true"
            app:title="@string/prefsAlertNbOfDays" />
        <SwitchPreference
            app:defaultValue="true"
            app:key="prefsAlertNotif"
            app:title="@string/prefsAlertNotifTitle" />
        <SwitchPreference
            app:defaultValue="false"
            app:key="prefsAlertEmail"
            app:title="@string/prefsAlertEmailTitle" />
        <SwitchPreference
            app:defaultValue="false"
            app:key="prefsAlertCal"
            app:title="@string/prefsAlertCalTitle" />
    </PreferenceCategory>
    <PreferenceCategory app:title="@string/prefsCatOthersTitle">
        <SwitchPreference
            app:defaultValue="false"
            app:key="prefsAlertAutoSync"
            app:title="@string/prefsAlertAutoSync" />
    </PreferenceCategory>
</PreferenceScreen>

Preference capture

Apart from the visualization problem, everything works fine and my preferences are well saved and usable in my java code.

I can't find what I'm doing wrong or what I'm missing.


Solution

  • Thanks to @cmak

    I never found this app:useSimpleSummaryProvider option before.