In the previous post I showed an example of how one can observe
EditText changes in the background. In this post I’ll cover how to combine several EditTexts changes in one chain and observe them in the background, too.
Assume we have three
EditTexts and each one of them should be checked before enabling/disabling the
Button. In order to observe all
CharSequences in one place, we will use
combineLatest()1 method in the
First, we need to create an
Observable of an
CharSequence which we will pass to the
combineLatest() method. We will use a RxBinding library for that. There are two requirements that we have:
rx.exceptions.MissingBackpressureException. In order to address this issue we will use
debounce()function like in the previous post.
- Observe everything in background.
Suppose we extracted the
Observable creation and named the method
rxTextView(), so that we can create three
Observables in the same manner. We can now pass all them to the
combineLatest() method we acquire a callback where we can process all emitted items of the
Observables which we passed to the method. This gives us an opportunity to return whatever object we want further. In the current example we will return
Boolean in order to enable/disable the button in our
This is an example of the callback we can have from three
In this callback we validate all the fields and pass a
Boolean further. And when subscribing we can enable/disable the
Don’t forget to save the
The sample project can be found here.
when an item is emitted by either of two Observables, combine the latest item emitted by each Observable via a specified function and emit items based on the results of this function ↩