0

我有两个可观察的:

 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( 

   */

}
4

1 回答 1

0

您是否尝试过 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

于 2017-07-08T17:08:05.497 回答