Is there a way to display the current PreferenceActivity setting?

I feel like something is missing, but I just don’t understand what it is. I have a PreferenceActivitybunch of different settings (some are lists, some are just text fields), and it all works fine, but if I don’t explicitly write each value of the element in the summary (which is clearly not intended for this purpose), I don’t see how (or where) the elements display what they are currently installed on. When I click on them, various views are displayed with the correct settings, but this is clearly not the intention.

Should I create my own custom list item that has a field displaying the current populated value of each item?

+3
source share
4 answers

Unfortunately, the PreferencesActivity settings do not display default values: what you do is really suitable if you want all the settings to be displayed at a glance.

+2
source

If you still want to move in the direction of programming, look at this thread: How to display the current value of Android preferences in the preferences summary?

There is everything.

+2
source

: . . "" , , / , .

+1

ListPreferences ,

android:summary="Actual value: %s"

For EditTextPreferencesyou can easily create your own class :

package your.package.preference;

import android.content.Context;
import android.util.AttributeSet;

public class EditTextPreference extends android.preference.EditTextPreference{
        public EditTextPreference(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }

        public EditTextPreference(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

        public EditTextPreference(Context context) {
            super(context);
        }

        @Override
        public CharSequence getSummary() {
            String summary = super.getSummary().toString();
            return String.format(summary, getText());
        }
    }

And use this in your xml:

<your.package.EditTextPreference
                android:key="pref_alpha"
                android:summary="Actual value: %s"
                android:title="Title"
                android:defaultValue="default"
                />
0
source

All Articles