tags:

views:

33

answers:

2

Hello everyone,

I want to use a control similar to Swing JSpinner in an Android application. I know that Android has a widget called Spinner, but it's more like a combo box than a JSpinner. I've noticed that DatePicker and TimePicker widgets are using components that are just like JSpinner. The only problem is that I don't really want Date or Time. I just want to get some integer, say from 1 to 50, that user chooses. Is this possible? I've searched Android API reference in and out, but I couldn't find any clue on how to do this. Any help or hint would be much appreciated.

Thanks, Tomislav

A: 

Well, the functionality for the TimePicker is provided by a hidden internal class named NumberPicker, which would probably be exactly what you wanted if only the folks at Google had made it available.

You might want to go to the android source code and lookup the source to android.widget.NumberPicker in the frameworks/base repository. (The repository treats it as if it were a publicly available class, though I see no sign of it in the released dev jars.)

beekeeper
Thanks, beekeper. I was refusing to believe that Google chose to hide that class. I thought I wasn't reading the docs thoroughly enough. Now that you provided me with the name of the class, I found someone already extracted it from source, along with appropriate drawables and layouts for usage in a preferences. So here it is: http://www.quietlycoding.com/?p=5
Tomislav
+1  A: 

I stole the spinner from Astrid, which stole it from Android's source.

Take a gander here:

http://github.com/ralphleon/TeaTimer/tree/master/src/goo/TeaTimer/widget/

Though my app is GPL, the number picker code is under the permissive Apache license!

Ralphleon