hour/minute picker for android countdown timer

http://stackoverflow.com/questions/3729068/hour-minute-picker-for-android-countdown-timer

 

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?

link | flag
  

2 Answers

up vote 0 down vote

I hope this code may help u

// step 1.create ur own count down timer

   
class MyCount extends CountDownTimer {
           
public MyCount(long millisInFuture, long countDownInterval) {
             
super(millisInFuture, countDownInterval);
           
}

           
public void onFinish() {
                dialog
.dismiss();
           
}

           
@Override
           
public void onTick(long millisUntilFinished) {
               
// TODO Auto-generated method stub

           
}
               
}
// step2. Invoke ur timer
MyCount counter = new MyCount(5000, 1000);
counter
.start();
link | flag
  
up vote 0 down vote

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.

Object o = findViewById(ids[i]);
Class<? extends Object> c = o.getClass();
Method m = c.getMethod("setCurrent", int.class);
current
= (int)(state / Math.pow(10, 3-i));
state
= state - current * (int)Math.pow(10, 3-i);
m
.invoke(o, current);

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"  />

Good luck.

link | flag

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值