Android - To measure the time between the two button clicks

后端 未结 3 1470
南旧
南旧 2021-01-01 18:08

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 t

3条回答
  •  既然无缘
    2021-01-01 18:46

    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 will give you the difference in seconds. Hope this helps.

提交回复
热议问题