1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| btnVerifyCode.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { btnVerifyCode.setEnabled(false); Observable.interval(0, 1, TimeUnit.SECONDS) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(AndroidSchedulers.mainThread()) .limit(31) .map(new Func1<Long, Long>() { @Override public Long call(Long aLong) { return 30 - aLong; } }) .doOnSubscribe(new Action0() { @Override public void call() { btnVerifyCode.setEnabled(false); } }) .doOnCompleted(new Action0() { @Override public void call() { btnVerifyCode.setEnabled(true); btnVerifyCode.setText("重新发送"); } }) .subscribe(new Action1<Long>() { @Override public void call(Long aLong) { btnVerifyCode.setText("重新发送("+aLong + " s )"); } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { ToastUtils.showCustomBgToast("获取失败,错误信息:" + throwable.getMessage() + ""); } }); } });
|