Countdown with textview

前端 未结 2 1067
轮回少年
轮回少年 2020-12-19 04:35

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

2条回答
  •  萌比男神i
    2020-12-19 05:19

    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();
    

提交回复
热议问题