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()'调用;为什么不直接注入服务? –
可否请您解释更多关于直接注入服务的信息?我仍然是这种东西的新手。 –