直接進入程式碼看看(下文程式參考於CountDownTimer)
public class TimerDemoActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView)findViewById(R.id.timer);
// CountDownTimer(倒數計時總長,倒數計時間隔)
new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
tv.setText("seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
tv.setText("done!");
}
}.start();
}
// 用來呈現的TextView
private TextView tv = null;
}