Android中短信发送倒计时方法

来源:互联网 发布:ajax json servlet 编辑:程序博客网 时间:2024/04/28 02:23
// 验证码等待
private int time = 90;
private static final int MSG_TIME = 0;
private static final int MAX_TIME = 90;
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case MSG_TIME:
if (time>0) {
time--;
get_verifyTextView.setText("重新获取" + time);


handler.sendEmptyMessageDelayed(MSG_TIME, 1000);
Log.i("TAG", "不停发消息的事件"+time);
} else {
get_verifyTextView.setText("获取验证码");
time = MAX_TIME;
}
break;
 
}
}
};



/**点击监听*/
@Override
public void onClick(View v) {
String tel = telEditText.getText().toString();
String input_verify = verifyEditText.getText().toString();
switch (v.getId()) {
case R.id.tv_get_verify_phone:
// 如果手机号与原来相同,不做请求


// 正确格式手机号
if (!ValidateUtil.isMobileNO(tel)) {
ShowDialog(MyApplication.mResources.getString(R.string.test_tel));
return;
}
// 90秒内不重新发送
if (time != 90&&time!=-1) {
UIHelper.showToast(this, time + "秒后可重新获取验证码");
return;
}



MyApplication.mRequestManager.getVerify(tel, this);
TemporaryTel = tel;
break;
0 0
原创粉丝点击