5

How can I build something like this? I wanna open a dialog in the Preferences Activity, where the user can change the number with a spinner, when he clicks on the according preference item.

Screenshots from the Android Messaging app's settings. Selecting an item defined by a Preference opens an interface to change the setting.

I got the screenshot from Android Developer Tools, but I cannot find some example code.

Niklas
  • 23,674
  • 33
  • 131
  • 170
  • Just to avoid confusion: the widget shown in the screenshot is a "picker" instead of a "spinner" – Gerd Feb 18 '16 at 14:24

2 Answers2

2

I have developed a Custom Preference, which can be found here.

XML Code:

<com.vanniktech.vntnumberpickerpreference.VNTNumberPickerPreference
    android:defaultValue="@integer/font_size_default_value"
    android:key="preference_font_size"
    android:title="@string/font_size"
    app:vnt_maxValue="@integer/font_size_max_value"
    app:vnt_minValue="@integer/font_size_min_value" />

Gradle include:

compile 'com.vanniktech:vntnumberpickerpreference:1.0.0'
Niklas
  • 23,674
  • 33
  • 131
  • 170
0

Launch the Spinner/picker in the preference's event handler:

final EditTextPreference msgLimitPref = (EditTextPreference)
                                 findPreference("prefMsgLimit");
                         msgLimitPref.setOnPreferenceClickListener(new
                                 OnPreferenceClickListener() {
                                 @Override
                                public boolean onPreferenceClick(Preference preference) {
                                     msgLimitPref.getDialog().dismiss();
                                   //launch spinner/numberpicker/activity/dialog here
                                 return true;
                                 }
                                 });
Nana Ghartey
  • 7,901
  • 1
  • 24
  • 26