4

I've made a numberpicker dialog. It looks like the image on the left, but without the up/down arrows:

enter image description here

How can I add them?

Here's my code:

public class NumberPickerFragment extends DialogFragment
                            implements DialogInterface.OnClickListener {

    protected final String CLS = this.getClass().getSimpleName();

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // TODO: Make this more flexible
        NumberPicker np = new NumberPicker(getActivity());
        np.setMaxValue(250);
        np.setMinValue(100);
        np.setValue(150);
        np.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
        np.setWrapSelectorWheel(false);

        return new AlertDialog.Builder(getActivity())
            .setTitle(R.string.height)
            .setView(np)
            .setPositiveButton(android.R.string.ok, this)
            .create();
    }

    @Override
    public void onClick(DialogInterface dialog, int whichButton) {
        // TODO: Do something with the return value
        Log.d(CLS, "Received click");
    }
}
jbrown
  • 7,518
  • 16
  • 69
  • 117
  • make custom number picker to achieve this. – TheFlash May 27 '13 at 09:58
  • Oh is there no default for this? I was hoping to just call a method on the picker to add those arrows. – jbrown May 27 '13 at 10:06
  • no there is no default for this..so check this link and if it helps to you then i will post it as answer..http://www.androidhub4you.com/2013/03/custom-picker-in-android-number-picker.html – TheFlash May 27 '13 at 10:10
  • is link provided by me useful?if yes can you please accept my anwer? – TheFlash May 27 '13 at 10:29
  • This http://stackoverflow.com/questions/17993192/android-number-picker-default-design-changes-in-jelly-bean-and-ice-cream-sandwit/35873140#35873140 might provide a useful information about each mode the NumberPicker can be displayed. – Montri M Mar 08 '16 at 16:53

1 Answers1

1

In Android, NumberPicker has two flavours - One with up down button and other with wheel scroll implementation.

Depending on the your current theme, NumberPicker is presented to the user.

Source: http://developer.android.com/reference/android/widget/NumberPicker.html

Also, if you look into the source code of NumberPicker, up/down ImageButtons are only enabled if NumberPicker layout, as defined by your Theme's style is equal to default R.layout.number_picker

Anirudh
  • 389
  • 1
  • 7
  • My theme is Holo.Light. Is there a simple way of enabling the buttons? I don't have time to implement them unless it's really simple. – jbrown May 27 '13 at 10:54
  • 2
    Well that explains. If you want to enable button, you can simply create your custom theme using this theme as parent theme and override NumberPicker_internalLayout style to use layout R.layout.number_picker. – Anirudh May 27 '13 at 12:14