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

安卓按钮60秒获取一次验证码

2014-07-17 14:04 204 查看
这是封装好的60秒获取验证码工具类

import android.os.CountDownTimer;
import android.widget.Button;

public class TimerCount extends CountDownTimer{

private Button bnt;

public TimerCount(long millisInFuture, long countDownInterval, Button bnt) {
super(millisInFuture, countDownInterval);
this.bnt = bnt;
}

public TimerCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
// TODO Auto-generated constructor stub
}

@Override
public void onFinish() {
// TODO Auto-generated method stub
bnt.setClickable(true);
bnt.setText("获取验证码");
}

@Override
public void onTick(long arg0) {
// TODO Auto-generated method stub
bnt.setClickable(false);
bnt.setText(arg0 / 1000+"秒后重新获取");
}
}

调用方法:
TimerCount timer=new TimerCount(60000,1000,getCode);
timer.start();这样即可时间效果,简单实用。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息