RxJava过滤器列表里面有observable

时间:2017-11-16 14:30:20

标签: java android rx-java2

我有对象

响应

public class Response {
    private List<Content> content;

    public static class Content {
        private boolean rated;
    }
}

我希望按List<Content> content值过滤rated。我试着这样做

mResponseProvider.reponse()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .flatMapIterable(response -> response.getContent())
                .filter(content -> mAAA.isRated(content.getRated()))
                .toList()
                .subscribe(response -> {
                    doSomethingWithResponse(response);
                });

但问题是response中的.subscribe()List<Content>。如何使用.subscribe()的过滤值访问Response List<Content>个对象?

1 个答案:

答案 0 :(得分:0)

mResponseProvider.reponse()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .filter(response -> mAAA.isRated(response.getContent())) //1
            .subscribe(response -> {
                doSomethingWithResponse(response);
            });

// 1尝试将参数更改为isRated中的List