Set the number of visible items in the NumberPicker

I have a simple one NumberPicker

like this:

NumberPicker

and I was wondering how I can show it more items above and below the selected item.

For example, in the picture you see "9" above the selected item "10" and "11" directly below it.

I would like to change the number of visible rows so that they show more items like "7, 8, 9", then the selected item "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 tried changing the setting android:layout_height

to match_parent

and to a large number (like 500dp) but it didn't see it work ...

+3


source to share


2 answers


Finally, I can find a workaround for this problem. You need to extend the class NumberPicker

and change

private static final int SELECTOR_WHEEL_ITEM_COUNT = 3;

      



three to more desired, but will be displayed according to the available space.

You can find the library and sample here .

+2


source


There doesn't seem to be a way to do this unless you rewrite the integer picker.



0


source







All Articles