I am using RxJava and RxBindings for view in android. following is an example of what I am doing.
RxView.clicks(btMyButton).flatMap(btn -> {
// another observable which can throw onError.
return Observable.error(null);
}).subscribe(object -> {
Log.d("CLICK", "button clicked");
}, error -> {
Log.d("CLICK", "ERROR");
});
when I click on MyButton, I use flatMap to return another observable which is a network call and can return success or error. when it returns an error i handle it in error block. but I am not able to click the button again.
How can I handle the error and still be able to click on the button again?
GreyBeardedGeek is spot on. To be quite explicit about one of your options you can use .materialize()
:
RxView.clicks(btMyButton).flatMap(btn -> {
if (ok)
return someObservable.materialize();
else
return Observable.error(new MyException()).materialize();
}).subscribe(notification -> {
if (notification.hasValue())
Log.d("CLICK", "button clicked");
else if (notification.isOnError())
Log.d("CLICK", "ERROR");
});
By the way don't pass null to Observable.error()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With