繁体   English   中英

如何在Android中通过翻新处理rxjava中项目列表的每个迭代

[英]How to process each iteration of list of items in rxjava with retrofit in Android

我是RxJava编程的新手,我想问一下如何处理翻新调用中的列表的每个迭代。 基本上我想做的是:

  1. 获取约会列表
  2. 迭代每个约会并获取Patient_id和subservice_id
  3. 转换回约会列表

到目前为止,这是我的代码

Observable<List<Appointment>> callAppointments = appointmentServiceRx.getService().getConfirmedAppointments(user_id);
    callAppointments.subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .flatMapIterable(apps -> apps)
            .concatMap(app -> getPatientById(app)
                    .doOnNext(this::addPatientNames)
                    .map(patient -> app)
            ).concatMap(app -> getSubserviceById(app)
                    .doOnNext(this::addSubserviceNames)
                    .map(subservice -> app)
            ).toList()
            .subscribe(res -> doStuff(),
                    throwable -> showThrowable());

请帮助并提前感谢您...

首先在observeOn(AndroidSchedulers.mainThread())调用会强制所有后续运算符在主线程上运行,然后抛出NetworkOnMainThreadException

尝试将此呼叫移至subscribe之前的最后一点:

// ...
.observeOn(AndroidSchedulers.mainThread())
.subscribe(res -> doStuff(),
    throwable -> showThrowable());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM