2
我的代碼如下。如何將每個項目添加到RxJava列表中Android
Observable<List<Appointment>> callAppointments = appointmentServiceRx.appointmentService.getConfirmedAppointments(user_id);
callAppointments
.flatMapIterable(appointments -> appointments)
.flatMap(app -> Observable.zip(
app,
patientServiceRx.patientService.getPatientById(app.patient_id),
servicesRestRx.servicesAPIServiceRx.getSubserviceById(app.subservice_id),
(appointment, patient, subservice) -> this.createListItem(appointment, patient, subservice)
))
.toList()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe();
隨着helper方法如下
private Observable<AppointmentListItem> createListItem (Appointment app, Patient patient, Subservice subservice){
AppointmentListItem item = new AppointmentListItem(app.appointment_id, subservice.subservice_name,
patient.patient_fullname, app.appointment_datetime);
return Observable.just(item);
}
我得到了一個錯誤,指出預期的參數和實際參數時,我試着打createListItem在Observable.zip
不匹配這是錯誤消息。
請幫助.....
啊我明白了。那麼如何將每個結果調用檢索到Appointment對象而不是使用字段呢?任何建議? –
我編輯了原文。我也想知道爲什麼你使用'getService()'調用;爲什麼不直接注入服務? –
可否請您解釋更多關於直接注入服務的信息?我仍然是這種東西的新手。 –