类似于标题栏中倒计时的样式:
自定义CountDownTimer
class MyCountDown extends CountDownTimer{
public MyCountDown(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onTick(long millisUntilFinished) {
minute = (int) (millisUntilFinished/60000);
second--;
if(second<0){
second = 59;
}
showTimeStr();
}
@Override
public void onFinish() {
second = 0;
showTimeStr();
//提交
}
}
初始化,调用
private int minute,second;
minute = 5;
second = 0;
countDown = new MyCountDown(60000*minute,1000);
countDown.start();
textview的刷新
private void showTimeStr() {
String time = new String();
if(second/10>0){
time = minute+":"+second;
}else{
time = minute+":0"+second;
}
tvChallengeTime.setText(time);
}