Hello,
at first sorry for my bad Englisch, I am coming form Germany ;D.
Okay, i have a problem with a Thread in Android, I want to make a stopping watch. So my first try was to make a thread which refreshs a TextView every second. But when i call TextView.setText("str"), the program always crashes. I really don't know why, so please help me. Thank you
The Code:
import android.widget.TextView;
at first sorry for my bad Englisch, I am coming form Germany ;D.
Okay, i have a problem with a Thread in Android, I want to make a stopping watch. So my first try was to make a thread which refreshs a TextView every second. But when i call TextView.setText("str"), the program always crashes. I really don't know why, so please help me. Thank you
The Code:
import android.widget.TextView;
Code:
public class Clock {
private boolean isStarted = false;
clockThread thread;
TextView millisecondsView;
public Clock(TextView millisecondsView) {
this.millisecondsView = millisecondsView;
}
public void count() {
if(!isStarted) {
isStarted = true;
thread = new clockThread();
if(!thread.isAlive())
thread.start();
}
else {
isStarted = false;
if(!thread.isAlive())
thread.interrupt();
}
}
private class clockThread extends Thread {
@Override public void run() {
millisecondsView.setText("SAD"); //here is the crash
//the millisecondsView Object comes from the main Activity
}
}
}