五、获取验证码倒计时
场景描述:
点击获取验证码后60s后可以再次点击获取。
问题分析:
计时和计数问题
伪代码实现:
TextView codeView;
int MAX_COUNT=60;
codeView.setEnabled(false);
Observable.intervalRange(0, MAX_COUNT, 0, 1, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<Long>() {
@Override
public void accept(Long aLong) throws Exception {
codeView.setText((MAX_COUNT-aLong)+"秒后重试");
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
}
}, new Action() {
@Override
public void run() throws Exception {
codeView.setText("获取验证码");
codeView.setEnabled(true);
}
});
网友评论