问题
My objective is to display a simple timer clock on my screen where it starts from 20 and goes on decreasing and when it becomes 0 I want to start an action. How to achieve this ? Thanks in advance
回答1:
I don't know how you want to display it but you can do this also just by taking a TextView and keep changing its Text every second.
static int i = 20;
new CountdownTimer(20000, 1000) {
public void onTick(long millisUntilFinished) {
i = i-1;
mTextField.setText(String.valuOf(i));
}
public void onFinish() {
//do your stuff here
}
}.start();
来源:https://stackoverflow.com/questions/7592863/showing-timer-in-android