如果我使用rxjava转换器进行改造以获得响应,我可以在何处以及在何处过滤结果(例如,对于一个列表<>用户,例如属性boolean paidDues = true
)?< / p>
Observable<User> observable = userService.me();
observable.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<User>() {
@Override
public void onCompleted() { // handle completed }
@Override
public void onError(Throwable e) { // handle error }
@Override
public void onNext(User user) { // handle response }
});
答案 0 :(得分:2)
使用过滤器:
Observable<User> observable = userService.me();
observable.observeOn(AndroidSchedulers.mainThread())
.filter(new Predicate<User >() {
@Override
public boolean test(@NonNull final User user) throws Exception {
return user.hasPaidDues(); // or something like this
}
})
.subscribe(...);