Android 使用CountDownTimer实现倒计时的功能
来源:互联网 发布:nas网络存储器 编辑:程序博客网 时间:2024/06/05 18:35
Android 使用CountDownTimer实现倒计时的功能
“`package com.alex.countdowntimer;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView tv;
private MyCount mc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView)findViewById(R.id.show);
mc = new MyCount(60000, 1000);
mc.start();
}
class MyCount extends CountDownTimer{ public MyCount(long millisInFuture, long countDownInterval) { super(millisInFuture, countDownInterval); System.out.println("Hello"); } @Override public void onTick(long millisUntilFinished) { Date date = new Date(millisUntilFinished); SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss"); String str = sdf.format(date); System.out.println(str); tv.setText("请等待"+millisUntilFinished / 1000 +"秒"); } @Override public void onFinish() { tv.setText("finish"); } } @Overrideprotected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); mc.cancel();}
}
第一个参数表示总时间,第二个参数表示间隔时间。意思就是每隔一秒会回调一次方法onTick,然后10秒之后会回调onFinish方法。
1 0
- Android 使用CountDownTimer实现倒计时的功能
- Android使用CountDownTimer实现倒计时功能
- android倒计时功能的实现(CountDownTimer)
- android倒计时功能的实现(CountDownTimer)
- android倒计时功能的实现(CountDownTimer)
- android倒计时功能的实现(CountDownTimer)
- android倒计时功能的实现(CountDownTimer)
- android倒计时功能的实现(CountDownTimer)
- Android倒计时功能的实现(CountDownTimer)
- Android 倒计时功能的实现(CountDownTimer)
- android倒计时功能的实现(CountDownTimer)
- android倒计时功能的实现(CountDownTimer)
- Android倒计时功能的实现(CountDownTimer)
- Android 倒计时功能的实现(CountDownTimer)
- android倒计时功能的实现(CountDownTimer)
- android倒计时功能的实现(CountDownTimer)
- android倒计时功能的实现(CountDownTimer)
- android倒计时功能的实现(CountDownTimer)
- HTTP深入浅出 http请求
- 使用Apache自带的ab命令测试网站性能(小强性能测试培训班学员作品)
- boost::thread用法
- JSON字符串转javabean,报net.sf.ezmorph.bean.MorphDynaBean cannot be cast to.....
- ACdream 1008 A Very Easy Triangle Counting Game(找规律)
- Android 使用CountDownTimer实现倒计时的功能
- Android apk 签名和多渠道打包
- Qt ContextMenu
- MYSQL 函数分类 以及储存过程使用经验
- Java之——汉字转换拼音(大小写)
- 2017/02/15 文献阅读
- C++常用字符串分割方法
- spring----filed值注入
- jdbcTools