KirstenLy
KirstenLy

Reputation: 1226

Observable.zip with RxBinding don't return result

I have two EditText, and i listening it with two observables:

Observable<CharSequence> emailObservable = RxTextView.textChanges(emailNew);
Observable<CharSequence> passwordObservable = RxTextView.textChanges(passwordNew);

I want to zip values from this fields to do some action when both values will valid.

So i wrote:

Observable.zip(emailObservable, passwordObservable, 
(charSequence, charSequence2) -> "test")
          .subscribe(result -> Timber.e("Result:" + result));

But it returns result only when second field data changed. When i type something at first field, it is not working.

Same result if i write:

emailObservable
    .zipWith(passwordObservable, (email, password) -> email + " " + password)
    .subscribe(result -> Timber.e(result);});

It returns correct values from first field, but return nothing if i type on it.

The answer must be ease, but now i can't understand what i do wrong.

Upvotes: 0

Views: 267

Answers (1)

KirstenLy
KirstenLy

Reputation: 1226

Ok, i replace zip to combineLatest and it works somehow:

Observable.combineLatest(emailObservable, passwordObservable,
                (charSequence, charSequence2) -> new String[]{charSequence.toString(), charSequence2.toString()})
                .subscribe(result -> {
                    boolean isEmailValid = isValidEmail(result[0]);
                    boolean isPasswordValid = isValidPassword(result[1]);
                });

Upvotes: 1

Related Questions