您的位置:首页 > 移动开发 > Android开发

Android 倒计时的实现

2013-12-12 11:02 92 查看
该方法参考了以下文章

http://blog.csdn.net/ithomer/article/details/6903084

public class timerTask extends Activity{
private int recLen = 0;
private TextView txtView;

public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);

setContentView(R.layout.timertask);
txtView = (TextView)findViewById(R.id.txttime);

handler.postDelayed(runnable, 1000);
}

Handler handler = new Handler();
Runnable runnable = new Runnable() {
@Override
public void run() {
recLen++;
txtView.setText("" + recLen);
handler.postDelayed(this, 1000);
}
};
}
以下方法为自己整理的

CountDownTimer countDownTimer = new CountDownTimer(8000, 1000) {
// millisUntilFinished:表示剩余的时间
@Override
public void onTick(long millisUntilFinished) {
textView1.setText("seconds remaining: " + millisUntilFinished / 1000 + 1);

}

// 计时结束时的操作
@Override
public void onFinish() {
textView1.setText("Bomb !!!!!");
}
};
countDownTimer.start();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: