两粒扣点击之间的时间 [英] Time between two button clicks

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

问题描述

从来就两个按钮,我想算两次点击之间的时间。我知道该怎么做一次:

I´ve two buttons and I want to count the time between two clicks. I know how to do that once:

 Long starttime = System.currentTimeMillis();
 Long endtime = System.currentTimeMillis();
 Long differenz = ((endtime-starttime) / 1000);

现在,我想在第二次点击,即计数从零重新开始的第一个按钮被点击,直到。然后测量第一和第二个按钮点击等之间的时间。

Now, I want on the second click, that the count starts from zero again until the first button is clicked. Then, measure the time between first and second button click and so on.

也许一个汇入作业非常简单的事情,但我不知道该怎么办...

Maybe it´s a really simple thing but I don´t know how to do...

编辑:确定,我尽量说清楚:

Ok, I try to make it clear:

我有按钮A和B.我希望用户交替推钮A和B.当A按钮用户点击,我想B被点击,直到计时器来测量时间。直到这里,一切都清楚了我。
现在我想从第B直到点击到A的点击之间的时间测量,总是A和B之间交替

I have Button A and B. I want the user to alternately push button A and B. When the user clicks on Button A, I want a timer to measure the time until B is clicked. Until here, everything is clear to me. Now I want that the time between the click on B till the click to A is measured, always alternated between A and B.

我不知道时间被再次测量,直到A. B上的点击后做什么

I don´t know what to do after the click on B that the time is measured again until A.

推荐答案

类成员

boolean mButtonAClicked;
boolean mButtonBClicked;

long mStartTime = 0;

当按钮被点击A

if (mButtonAClicked)
{
    // button A is clicked again, stop application
}
else
{
    mButtonAClicked = true;
    mButtonBClicked = false;
    if (mStartTime != 0) // Button B was clicked
    {
         Long endtime = System.currentTimeMillis();
         Long differenz = ((endtime-starttime) / 1000);
         mStartTime = System.currentTimeMillis();
    }
}  

当按键B被cliked

When Button B is cliked

if (mButtonBClicked)
{
    // button B is clicked again, stop application
}
else
{
    mButtonBClicked = true;
    mButtonAClicked = false;
    if (mStartTime != 0) // Button A was clicked
    {
         Long endtime = System.currentTimeMillis();
         Long differenz = ((endtime-starttime) / 1000);
         mStartTime = System.currentTimeMillis();
    }
}  

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

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