siraj siraj - 1 year ago 57
Android Question

Android - To measure the time betweeen the two button clicks

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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download