安卓开发之Chronometer的快速获取…

来源:互联网 发布:cocos2d-js api 编辑:程序博客网 时间:2024/06/03 21:39
private Chronometer timer;
timer.stop();
timer.start();

这些基本的就不说了。
其实也就是算法的问题,
int temp0 = Integer.parseInt(timer.getText().toString().split(":")[0]);
int temp1 =Integer.parseInt(timer.getText().toString().split(":")[1]);
int temp=temp0*60+temp1;
解释一下,split是根据里面的分割符号取值的一个函数,百度下可以查找到基本用法。
对于本例子。 时间输出的格式一般是00:00
因此temp0取 第一个 00,的分钟的值。 索引是[0],取 第二个 00,是秒的值。索引是[1]
则算出的总的秒的值即是 temp.

0 0