6

I have a simple NumberPicker just like this:

NumberPicker

and I was wondering how I can make it show more elements above and below the selected element.

For example, in the picture you can see "9" above the selected element "10", and "11" right below it.

I would like to change the number of visible rows so it shows more elements like "7, 8, 9", then the selected element "10", then "11, 12, 13".

This is my code:

<NumberPicker
    android:id="@+id/picker"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="15dp"
    android:gravity="center"
    android:textColor="@android:color/white"
    android:textSize="16sp"
    />

and I've tried to change setting android:layout_height to match_parent and to a big number (e.g. 500dp) but it doesn't seen to work...

Mike Laren
  • 8,028
  • 17
  • 51
  • 70

2 Answers2

0

Finally I am able to find a workaround for this problem. You need to extend your NumberPicker class and need to change the

private static final int SELECTOR_WHEEL_ITEM_COUNT = 3;

from three to more as much you wish, but it will display according to the available space.

You can find a library and sample here.

Sanjeet A
  • 5,171
  • 3
  • 23
  • 40
0

Seems there is not way to do that, unless you rewrite whole numberpicker.

Jason Hu
  • 31
  • 6