2016-10-31 8 views
0

は私が持っているObservableのように:私は今持っている観測可能 - 購読する二つの方法

Observable<Integer> dropdownChange =  ReactiveUIObservables.selectionChange(myDropdown) 

LifecycleObservable.bindFragmentLifecycle(lifecycle(), dropdownChange) 
    .ObserveOn(AndroidSchedulers.mainThread)) 
    .SubscribeOn(AndroidSchedulers.mainThread()) 
    .subscribe(this::onDropdownChange); 

そして、それは働いているが、今DropdownChange後、私はselectionChangeに別の方法を実行したいです。どうやってするの?

答えて

1

subscribeを使用すると、複数のメソッドを呼び出すことができます。例えば。

subscribe(myValue -> { 
     onDropdownChange(myValue); 
     // call the other method 
}); 
0

すべてのサブスクライバが同じイベントを受信する必要がある場合は、ConnectableObservableを使用できます。 .connect()を呼び出すまで、イベントは送出されません。

Observable<Integer> dropdownChange = ReactiveUIObservables.selectionChange(myDropdown); 
ConnectableObservable<Integer> connectableDropdownChange = dropdownChange.publish(); 

connectableDropdownChange.subscribe(this::onDropdownChange); 
connectableDropdownChange.subscribe(this::doSomething); 
connectableDropdownChange.subscribe(this::doSomethingElse); 

// start emitting events 
connectableDropdownChange.connect(); 
関連する問題