views:

196

answers:

2

I'm trying to implement something like a countdown timer that plays an alarm at 0. I want to be able to set the amount of time to wait before the timer goes off and I'm wondering if there's a UI widget or element that provides this kind of selection functionality.

Basically, does android have something like the iPhone's selection spinwheel? Or is there some type of timepicker that allows selection of an arbitrary number of hours and minutes? The timepicker widget in android has an unnecessary AM/PM label.

Do I need to implement my own custom UI to achieve this?

+1  A: 

Yes, you can hack one together. It's a distinct possibility that this code will have a short lifespan though due to changes in the API.

int foo = 7;
Object o = findViewById(ids[i]);
Class<? extends Object> c = o.getClass();
Method m = c.getMethod("setCurrent", int.class);
m.invoke(o, foo);

String[] displayedValues = new String[] { "$00", "$01", "$02", "$03", "$04", 
                        "$05", "$06", "$07", "$08", "$09", "$10", "$11", 
                        "$12", "$13", "$14", "$15", "$16", "$17", "$18", "$19", "$20", "$21", 
                        "$22", "$23", "$24", "$25"};
Method m = c.getMethod("setRange", int.class, int.class, String[].class);
M.invoke(o, 0, 25, displayedValues);

And then drop a couple of these in your layout:

<com.android.internal.widget.NumberPicker
android:id="@+id/picker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"  />

setCurrent set's the index of the picker which in the case of foo means a value of "$07". setRange sets the values to display in the picker.

Good luck.

Neil D
what is "state"?
pengwang
pengwang, i hope that edit clarifies things. let me know if it does not.
Neil D