如何在Android中反向启动天文钟? [英] How to start chronometer in reverse in android?

查看:293
本文介绍了如何在Android中反向启动天文钟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

cmtr.setText(finalTime);
cmtr.setBase(SystemClock.elapsedRealtime());

timetest = SystemClock.elapsedRealtime();
Log.d("SETTIME: ", ""+timetest);
cmtr.start();

eltime = SystemClock.elapsedRealtime();
Log.d("ELapsed: ", ""+eltime);

注意:我想以相反的顺序启动天文钟.就像我将天文钟设置为10秒一样.现在,我想以相反的顺序从10秒开始到0秒.所以任何人都可以帮助获得此解决方案.提前非常感谢您.

Note: i want to start my chronometer in reverse order. like i set chronometer 10 seconds. now, i want to start from 10 to 0 seconds in reverse order. so can anyone help to get this solution.? Thank you so much in advance.

推荐答案

您不能, CountDownTimer (Android SDK页面包含一个更新TextView的特定示例),或推出您自己的解决方案.

You can't, the Chronometer widget only counts up, that's the specific purpose it was made for. If you want to count down, use the CountDownTimer (the Android SDK page contains a specific example where a TextView is updated), or roll your own solution.

这些类是琐碎的包装程序,可节省您一些键入操作.如果它们不能满足您的确切需求,您真的应该不会感到不舒服.

These classes are trivial wrappers to save you some typing. You really shouldn't feel uncomfortable writing an alternative implementation if they don´t fit your exact needs.

[更新]

正如罗纳尔多·巴伊亚(Ronaldo Bahia)在评论中所添加的那样,由于API 24计时码表实际上是通过

As Ronaldo Bahia added in the remarks, since API 24 the Chronometer actually offers this functionally through the setCountDown method.

这篇关于如何在Android中反向启动天文钟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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