Android: simple time counter

后端 未结 6 2224
-上瘾入骨i
-上瘾入骨i 2020-12-09 02:56

I have a simple program with one TextView and two Buttons: Button1 and Button2.

Clicking on Button 1 will start a counter, increasing by 1 every 1 second and show res

6条回答
  •  感情败类
    2020-12-09 03:31

    This way it is much simpler. It is a feature made available on the android developer site. Link

    public void initCountDownTimer(int time) {
        new CountDownTimer(30000, 1000) {
    
            public void onTick(long millisUntilFinished) {
                textView.setText("seconds remaining: " + millisUntilFinished / 1000);
            }
    
            public void onFinish() {
                textView.setText("done!");
            }
        }.start();
    }
    

提交回复
热议问题