我有两项退货服务:
可观测= api.getCategories();可观测= api.getProdutcs();
如何使用RxJava执行两个服务?,这两个服务都不扩展/依赖
当2项服务完成后,我想通知RV类别和RV产品的适配器
发布于 2019-01-31 06:55:28
Observable.zip(api.getCategories()
,api.getProdutcs(),
BiFunction<List<Categories>, List<Product>, Pair<List<Categories>, List<Product>>> { t1, t2 -> Pair(t1, t2) })
).subscribeBy{
it.first//List<Category> update the adapter for category
ir.second //List<Product> update the adapter for product
}发布于 2019-01-31 06:43:40
bro调用此方法youradapterintance.notifyDataSetChanged();如果您正在调用webservices并在onCreate中设置适配器,那么您必须使用事件总线,一旦dataset更改,然后在onEventRecieve方法上设置适配器。
发布于 2019-01-31 06:48:26
如果您的api.getCategories()和api.getProdutcs()返回不同的类型,则可以在执行第一个之后订阅第二个可观察到的类型:
api.getCategories()
.subscribe(categories -> api.getProdutcs().subscribe(products -> //Here notify your lists ))或者您可以尝试使用zip操作符:
Observable
.zip(api.getCategories(), api.getProdutcs(), (categories, products) -> //Here you need to define type of return value )
.subscribe(yourObject ->//Here notify your lists );https://stackoverflow.com/questions/54454371
复制相似问题