Search code examples
androidlistviewandroid-custom-viewnumberpicker

Item picker in Android like NumberPicker


I want to create a View that holds multiple items just like a NumberPicker. The problem with NumberPicker is that the UI cannot be customized.Also I don't want the items to be editable.

Requirements

In landscape mode the list should appear on the left half of the screen with a selection band that is vertically centered. On the right half is a button, which will act on the selected item in the list. The first item in the list should be in the center. That means the list is infinitely scrollable.

What I have tried

I have tried listview with center gravity, but doesn't work. Tried custom view extending linear layout and tried to manipulate top margin. Failed.

Expected output

Expected result


Solution

  • The widget you're looking for is called WheelPicker and as always, there's already 3rd party libs just for this. Have a look.

    In landscape mode the list should appear on the left half of the screen with a selection band that is vertically centered.

    This could easily be done using appropriate styling and XML formatting.

    On the right half is a button, which will act on the selected item in the list. The first item in the list should be in the center. That means the list is infinitely scrollable.

    Again, appropriate styling and XML formatting.

    I suggest you delve into the source of that WheelPicker and see how you could tailor it to your liking.

    Hope this helps!