小时/分钟装载机安卓倒数计时器 [英] hour/minute picker for android countdown timer

查看:235
本文介绍了小时/分钟装载机安卓倒数计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现像一个倒数计时器,在0起着报警我希望能够设置的时间等待的定时熄灭,我不知道是否有一个UI部件或元素提供了这种选择功能。

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.

基本上,它已经的android类似iPhone的选择旋钮?或者是有一些类型的timepicker,允许选择的小时和分钟的任意号码?在Android上timepicker小部件有一个不必要的AM / PM标签。

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?

推荐答案

您可以使用默认TimePickerDialog并覆盖onTimeChanged方法来更新自己的标题:

You can use the default TimePickerDialog and override the onTimeChanged method to update the title yourself:

    public class DurationPickerDialog extends TimePickerDialog {

    public DurationPickerDialog(Context context, int theme,
            OnTimeSetListener callBack, int hour, int minute) {
        super(context, theme, callBack, hour, minute, true);
        updateTitle(hour, minute);
    }

    public DurationPickerDialog(Context context, OnTimeSetListener callBack,
            int hour, int minute) {
        super(context, callBack, hour, minute, true);
        updateTitle(hour, minute);
    }

    @Override
    public void onTimeChanged(TimePicker view, int hour, int minute) {
        super.onTimeChanged(view, hour, minute);
        updateTitle(hour, minute);
    }

    public void updateTitle(int hour, int minute) {
        setTitle("Duration: " + hour + ":" + formatNumber(minute));
    }

    private String formatNumber(int number) {
        String result = "";
        if (number < 10) {
            result += "0";
        }
        result += number;

        return result;
        }
}

这篇关于小时/分钟装载机安卓倒数计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆