如何显示当前时间动态变化的每一秒中的android [英] How to Display current time that changes dynamically for every second in android

查看:147
本文介绍了如何显示当前时间动态变化的每一秒中的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示当前时间在一个TextView和时间动态的每一秒的变化(如数字时钟)在Android的..我用Google搜索,但我没有得到help.If任何人有这个的想法,请帮我 先谢谢了。

I need to display the current time in a textview and the time changes dynamically for every second (Like the digital clock) in android.. I have googled but i didnt get the help.If Anyone have the idea for this, please help me Thanks in advance.

推荐答案

使用CountDownTimer类,通过一个巨大的价值(在这里我给10亿)的CountDownTimer生活。

Use CountDownTimer class , pass a huge value to (here I gave 1000000000) for CountDownTimer life .

样品code ::

CountDownTimer newtimer = new CountDownTimer(1000000000, 1000) { 

            public void onTick(long millisUntilFinished) {
                Calendar c = Calendar.getInstance();
                textView.setText(c.get(Calendar.HOUR)+":"+c.get(Calendar.MINUTE)+":"+c.get(Calendar.SECOND));
            }
            public void onFinish() {

            }
        };
        newtimer.start();

在关闭活动,请拨打以下函数

While closing the Activity, call the following function

newtimer.cancel();

这篇关于如何显示当前时间动态变化的每一秒中的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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