Android获取验证码倒计时
2015-03-18 11:51
423 查看
获取验证码倒计时,切换页面或finish后,计时持续不间断的简易使用方法:
public class Example extends Activity{ private Button getCode_btn;//获取验证码按钮 public static CountDownTimer getCode_CDtimer;// 获取验证码计时器 public static long timeRemain;// 时间剩余记录 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.example);//布局文件自己自定义 getCode_btn = (Button) findViewById(R.id.getCode_btn); if (Example .getCode_CDtimer != null) {// 如果获取验证码的计时器正在计时 Example .getCode_CDtimer.cancel();// 则获取当前剩余时间 timeRemain(Example .timeRemain);// 重新已剩余时间为基础计时 } } @Override public void onClick(View v) { switch (v.getId()) { case R.id.getCode_btn:// 获取验证码按钮被点击 getCode_btn.setEnabled(false);// 按钮不可点击 timeRemain(60l);// 时间设置60秒计时 break; } /** * * @param 时间 * 获取验证码时间计时器初始化 */ public void timeRemain(Long arg0) { Example .getCode_CDtimer = new CountDownTimer(arg0 * 1000, 1000) { @Override public void onTick(long arg0) { getCode_btn.setText(arg0 / 1000 + "秒");// 每隔1秒显示时间剩余 Example .timeRemain = arg0 / 1000;// 保存剩余时间 // Log.v("timer", Example .timeRemain +""); if (arg0 <= 0) { Example .timeRemain = 60l;// 计时完成剩余时间记录重置60s } } @Override public void onFinish() { getCode_btn.setText("获取验证码"); getCode_btn.setEnabled(true);// 60秒结束后按钮可点击 } }.start(); } }
相关文章推荐
- Android获取验证码后倒计时程序
- Android获取验证码时的倒计时 CountDownTimer使用
- Android获取验证码后倒计时
- android 获取验证码倒计时
- Android中获取验证码时的倒计时效果
- Android获取验证码后倒计时程序
- Android 获取验证码倒计时
- Android实现点击获取验证码倒计时效果
- android获取验证码实现倒计时
- Android 获取验证码后的倒计时功能
- android登陆获取验证码倒计时功能的实现(CountDownTimer)
- Android获取验证码后倒计时程序
- Android 获取手机手机验证码倒计时通用接口设计
- Android实现获取验证码的倒计时功能
- Android 获取验证码后 在Button控件上 显示倒计时
- android中获取手机验证码的倒计时操作
- android获取验证码倒计时功能
- Android 注册页面 设置显示或者隐藏密码 和 点击获取验证码倒计时60s