An Android Stopwatch TextView
The Chronometer class which is part of the standard Android SDK is useful for counting the number of milliseconds from a point in time. It does not however allow pause and restart like a normal stopwatch. I needed this type of functionality for my app, so I have extended Chronometer to provide this: public class StopWatch extends Chronometer { private long elapsedBeforePause; public StopWatch(Context ctx) { super(ctx); } public StopWatch(Context ctx, AttributeSet attrs) { super(ctx, attrs); } public void startClock() { setBase(SystemClock.elapsedRealtime()); super.start(); } public long stopClock() { long result = SystemClock.elapsedRealtime() - getBase(); super.stop(); return result; } public void pauseClock() { elapsedBeforePause = stopClock(); } public void restartClock() { setBase(SystemClock.elapsedRealtime() - elapsedBeforePause); elapsedBef...