RxJava 操作符处理表单验证 或者登录问题

Observable.combineLatest  方法使用

Observable.combineLatest<Observable1,Observable2,BiFunction<String,String,Bollean>>
    @SuppressWarnings("unchecked")
    @CheckReturnValue
    @SchedulerSupport(SchedulerSupport.NONE)
    public static <T1, T2, R> Observable<R> combineLatest(
            ObservableSource<? extends T1> source1, ObservableSource<? extends T2> source2,
            BiFunction<? super T1, ? super T2, ? extends R> combiner) {
        ObjectHelper.requireNonNull(source1, "source1 is null");
        ObjectHelper.requireNonNull(source2, "source2 is null");
        return combineLatest(Functions.toFunction(combiner), bufferSize(), source1, source2);
    }
例子方法1
Observable.combineLatest(RxTextView.textChanges(mRectEtMobile.mEditText),
        RxTextView.textChanges(mRectEtPwd.mEditText),
        BiFunction<CharSequence, CharSequence, Boolean> { mobile, password ->
            TextCheckUtil.checkMobilePhone(mobile.toString()) && password.length >= 6 && password.length <= 18
        })
        .compose(bindUntilEvent(ActivityEvent.DESTROY))
        .subscribe { aBoolean -> mBtnLogin.isEnabled = aBoolean }
例子方法2
Observable.combineLatest<String, String, Boolean>(
        RxTextView.textChanges(mRectEtMobile.mEditText).map { mobile -> mobile.toString() }
        , RxTextView.textChanges(mRectEtPwd.mEditText).map { password -> password.toString() }
        , BiFunction<String, String, Boolean> { mobile, password ->
    TextCheckUtil.checkMobilePhone(mobile) && password.length >= 6 && password.length <= 18
})
        .compose(bindUntilEvent(ActivityEvent.DESTROY))
        .subscribe { aBoolean -> mBtnLogin.isEnabled = aBoolean }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值