How to set timer in android?

后端 未结 21 1290
渐次进展
渐次进展 2020-11-22 00:51

Can someone give a simple example of updating a textfield every second or so?

I want to make a flying ball and need to calculate/update the ball coordinates every se

21条回答
  •  深忆病人
    2020-11-22 01:45

    If one just want to schedule a countdown until a time in the future with regular notifications on intervals along the way, you can use the CountDownTimer class that is available since API level 1.

    new CountDownTimer(30000, 1000) {
        public void onTick(long millisUntilFinished) {
            editText.setText("Seconds remaining: " + millisUntilFinished / 1000);
        }
    
        public void onFinish() {
            editText.setText("Done");
        }
    }.start();
    

提交回复
热议问题