Android countdown tool and android Tool
During our programming, we often use the countdown function. Many people do not know that Android has encapsulated a class and often write it by themselves. Now we have found this class. Share it with you:
The remaining time is continuously displayed in a TextView. The Code is as follows:
[Java]View plaincopy
- Private TextView vertifyView;
- Private CountDownTimer timer = new CountDownTimer (0, 10000,100 ){
- @ Override
- Public void onTick (long millisUntilFinished ){
- VertifyView. setText (millisUntilFinished/1000) + "resend in seconds ");
- }
- @ Override
- Public void onFinish (){
- VertifyView. setEnabled (true );
- VertifyView. setText ("Get Verification Code ");
- }
- };
It is easy to call: timer. start ();
Finally, in CountDownTimer timer = new CountDownTimer (10000,100 0), the first parameter indicates the total time, and the second parameter indicates the interval. This means that the method onTick will be called back every second, and then the onFinish method will be called back 10 seconds later.