I've got two observables - OnPeriodChanged and OnFilterChanged, and trying to figure out how to call a function for view adapter when one of them changes. I've tried .zip, but for some reason it does not get triggered:
Observable.zip(OnPeriodChanged, OnFilterChanged, (Date, Filter) -> HistoryViewModel.getScans(Date.first, Date.second, Filter)).subscribe(scans -> histAdapter.setScans(scans));
What I can use here to invoke the getter function and pass the results from it to setter?
zip
will emit the items to the downstream only after both of your observables ( OnPeriodChanged
, OnFilterChanged
) emitted. I think you are trying to call HistoryViewModel.getScans
whenever any of the item changes, with latest values of Date
and Filter
. You could use combineLatest
instead of zip
Try changing it to
Observable.combineLatest(OnPeriodChanged, OnFilterChanged, (Date, Filter) -> HistoryViewModel.getScans(Date.first, Date.second, Filter))
.subscribe(scans -> histAdapter.setScans(scans));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.