android 擷取簡訊驗證碼倒計時
android 擷取簡訊驗證碼倒計時
public class MainActivity extends Activity {
private Button submit;
private TimeCount time;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
time = new TimeCount(60000, 1000);
submit = (Button) findViewById(R.id.btn_login_submit);
submit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
time.start();// 開始計時
}
});
}
class TimeCount extends CountDownTimer {
public TimeCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {// 計時完畢
submit.setText(擷取驗證碼);
submit.setClickable(true);
}
@Override
public void onTick(long millisUntilFinished) {// 計時過程
submit.setClickable(false);//防止重複點擊
submit.setText(millisUntilFinished / 1000 + s);
}
}