Android Timer Example Implements Activity private Handler custom

  • Slides: 3
Download presentation
Android Timer Example

Android Timer Example

Implements Activity private Handler custom. Handler = new Handler(); start. Button = (Button) find.

Implements Activity private Handler custom. Handler = new Handler(); start. Button = (Button) find. View. By. Id(R. id. start. Button); start. Button. set. On. Click. Listener(new View. On. Click. Listener() { public void on. Click(View view) { start. Time = System. Clock. uptime. Millis(); custom. Handler. post. Delayed(update. Timer. Thread, 0); } }); pause. Button = (Button) find. View. By. Id(R. id. pause. Button); pause. Button. set. On. Click. Listener(new View. On. Click. Listener() { public void on. Click(View view) { time. Swap. Buff += time. In. Milliseconds; custom. Handler. remove. Callbacks(update. Timer. Thread); } });

 private Runnable update Timer. Thread = new Runnable() { public void run() {

private Runnable update Timer. Thread = new Runnable() { public void run() { time. In. Milliseconds = System. Clock. uptime. Millis() - start. Time; updated. Time = time. Swap. Buff + time. In. Milliseconds; int secs = (int) (updated. Time / 1000); int mins = secs / 60; secs = secs % 60; int milliseconds = (int) (updated. Time % 1000); timer. Value. set. Text("" + mins + ": " + String. format("%02 d", secs) + ": " + String. format("%03 d", milliseconds)); custom. Handler. post. Delayed(this, 0); } };