My goal is simple:
In my xml file,I have a textview called: textView2.
What I need is a countdown,that countsdown from 15 to 0,and every time a second passes
Try this:----
TextView textic = (TextView) findViewById(R.id.textView2);
CountDownTimer Count = new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
textic.setText("Seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
textic.setText("Finished");
}
};
Count.start();
I think it is the matter of updating a UI element from outside the UI thread
so try the following:
new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
final int j = (int) millisUntilFinished;
runOnUiThread(new Runnable() {
@Override
public void run() {
TextView textic = (TextView) findViewById(R.id.textView2);
textic.setText(j);
}
});
}
public void onFinish() {
}
}.start();