在我们注册或者修改信息的时候,常会用到60s倒计时这个功能,写了这篇文章,大家共享一下:

效果图:

直接上代码:

activity.java

 public class MainActivity extends Activity {

     private TimeCount mTiemTimeCount;
private TextView tv_code; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTiemTimeCount = new TimeCount(60000, 1000);
initView(); } private void initView() {
// TODO Auto-generated method stub
tv_code = (TextView) findViewById(R.id.verify_code);
tv_code.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
mTiemTimeCount.start();
}
});
} // 计时重发
private class TimeCount extends CountDownTimer { public TimeCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
} @Override
public void onTick(long millisUntilFinished) {
tv_code.setClickable(false);
tv_code.setText(millisUntilFinished / 1000 + "秒后重新发送");
} @Override
public void onFinish() {
tv_code.setText("获取验证码");
tv_code.setClickable(true);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
mTiemTimeCount.cancel();
}
}
mTiemTimeCount = new TimeCount(60000, 1000);可以自己更改时间  

代码简单可直接使用

源码下载: https://github.com/DickyQie/android-layout-controls

最新文章

  1. SQL Server-表表达式基础回顾(二十四)
  2. 史上最简单,一步集成侧滑(删除)菜单,高仿QQ、IOS。
  3. Mac10.9用brew搭建Eclipse4.4+Maven3.2.3+JDK1.8运行环境
  4. 加州大学伯克利分校Stat2.3x Inference 统计推断学习笔记: Section 4 Dependent Samples
  5. python学习之安装模块
  6. git撤销commit
  7. Swift - UIView的无损截图
  8. MySQL 获得当前日期时间(以及时间的转换)
  9. PHP抓取豆瓣读书爬虫代码
  10. CKRule BRMS-决策表使用说明
  11. 基于JSP+SERVLET的新闻发布系统(二)
  12. 基于Linux根据僵尸网络病毒平台《比尔盖茨》
  13. 运行ORB-SLAM笔记_编译篇(一)
  14. ucos信号量集源码分析
  15. linux-Centos6.5中nginx1.63源码安装
  16. Python实战之实现简单的登陆系统-作业
  17. C#中的GET和SET访问器
  18. redis集群配置与管理
  19. Collections.unmodifiableMap(Map map)
  20. Redux和react-redux的学习总结

热门文章

  1. Linux服务器---apache支持SSL
  2. QAQ的LIS树 QAQ的LIS树2 题解报告
  3. leetcode 136 Single Number, 260 Single Number III
  4. 利用构建缓存机制缩短Docker镜像构建时间
  5. SPOJ Prime or Not - 快速乘 - 快速幂
  6. 一种新的技术,C++/CLI
  7. Mysql相关问题收集
  8. [BZOJ4244]邮戳拉力赛
  9. C#入门经典 第六章 委托
  10. 论文笔记之:UNSUPERVISED REPRESENTATION LEARNING WITH DEEP CONVOLUTIONAL GENERATIVE ADVERSARIAL NETWORKS