It has been a while but I'm back to android development. I am creating a simple stopwatch app.
I have a Timer class and a TextView that i want to update constantly as time is running. I know I can create a thread that will update the TextView but I am not sure of how to do that. Should my Timer extend the thread?
How would the code look to update the textView on a time interval.
This is my Timer class:
public class Timer {
private double startTime;
private double endTime;
private boolean isRunning;
public Timer() {
startTime = 0;
endTime = 0;
isRunning = false;
}
public void reset() {
isRunning = true;
startTime = System.currentTimeMillis();
}
public double getElapsedTime() {
if (isRunning)
endTime = System.currentTimeMillis();
double timeElapsed = endTime - startTime;
return timeElapsed;
}
}
I also found this related question. But I cannot figure out how to make it work. I would appreciate any code that shows how to make the update happen with my code. I didn't include my MainActivity but it's the sample FullScreenActivity.