我有两个可观察量:
Observable <Profile> profileObservable = briteDatabase.createQuery(UserMapper.Table.NAME, sql, String.valueOf(userId)).mapToOneOrDefault(UserMapper.MAPPER, null);
Observable <List<Car>> carObservable = briteDatabase.createQuery(CarMapper.Table.NAME, sql, String.valueOf(userId)).mapToOneOrDefault(CarMapper.MAPPER, null);
public class Profile {
int id;
String name;
ArrayList<Car> car;
...
}
public class Car {
int id;
String brand;
...
}
我需要从carObservable获取汽车列表并将其放入profileObservable(将汽车列表放入Profile(,在方法中是这样的:
@Override
public Observable<Profile> getProfile(String userId) {
String sql = String.format("SELECT %s FROM %s WHERE %s=?", TextUtils.join(",", UserMapper.PROJECTION), UserMapper.Table.NAME, UserMapper.Columns.ID);
Observable <Profile> profileObservable = briteDatabase.createQuery(UserMapper.Table.NAME, sql, String.valueOf(userId)).mapToOneOrDefault(UserMapper.MAPPER, null);
Observable <List<Car>> carsObservable = getCars(String userId);
/*
Some important method to concat and return Observable <Profile>. I'm only beginner at RxJava(
*/
}
您是否尝试过concat运算符,我不知道我是否非常了解您的用例,但是如果您只需要浏览汽车列表然后配置文件,只需一个接一个地连接即可
@Test
public void testContact() {
Observable.concat(Observable.just("Hello"),
Observable.just("reactive"),
Observable.just("world"))
.subscribe(System.out::println);
}
如果你想在RxJava世界中启动,请看这里 https://github.com/politrons/reactive