我在
android中使用Rx
Java和RxBindings进行查看.以下是我正在做的事情的一个例子.
@H_404_2@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");
});
当我点击MyButton时,我使用flatMap返回另一个observable,它是一个网络调用,可以返回成功或错误.当它返回错误时我在错误块中处理它.但我无法再次点击该按钮.
如何处理错误并仍然可以再次单击按钮?
解决方法
GreyBeardedGeek就是现货.要明确你的一个选项,你可以使用.materialize():
@H_404_2@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");
});
顺便说一句,不要将null传递给Observable.error().