Android - 测量两次按钮点击之间的时间 [英] Android - To measure the time between the two button clicks

查看:36
本文介绍了Android - 测量两次按钮点击之间的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 Check In 的按钮.我的目标是单击以更改文本并开始计算时间.计时器必须在下一次单击时停止.它应该给出两次按钮点击之间的时间.

I have a button named Check In. My aim is on click to change the text and start counting the time. The timer has to stop at the next click. It should give the time taken between the two button clicks.

推荐答案

在第一次点击时创建一个变量:

On the first click create a variable:

long startTime = System.currentTimeMillis();

然后在第二次点击时,您可以计算出差异:

Then on the second click you can calculate the difference:

long difference = System.currentTimeMillis() - startTime;

difference/1000 会给你以秒为单位的差异.希望这会有所帮助.

difference / 1000 will give you the difference in seconds. Hope this helps.

这篇关于Android - 测量两次按钮点击之间的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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