I want to create an Observable
from view click listener using RxJava 2. I started from the simplest implementation (I don't use lambdas here to show you different types in this method):
Observable<View> viewObservable = Observable.create(new ObservableOnSubscribe<View>() {
@Override
public void subscribe(@NonNull ObservableEmitter<View> e) throws Exception {
mNewWordView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View value) {
if (!e.isDisposed()) {
e.onNext(value);
}
}
});
}
});
Then I thought about the way to set onClickListener
to null if it is not needed further. I found that there are two methods with similar (as for me) names:
e.setCancellable(Cancellable c);
and
e.setDisposable(Disposable d);
What is the difference between them and which should I use?
See Question&Answers more detail:os