Tolist不会在rxjava中发出

时间:2018-06-06 18:39:07

标签: android rx-java rx-java2

我尝试从edittext获取输入后过滤列表,实际上它过滤了列表,但我想将结果分组到列表。

所以我以前用SingleObserver列出运算符,但结果不会出现;这是为什么?

RxTextView.textChangeEvents(searchEdit)
                .skip(1)
                .debounce(400, TimeUnit.MILLISECONDS)
                .switchMap(new Function<TextViewTextChangeEvent, Observable<List<VehicleMakeModel>>>() {
                    @Override
                    public Observable<List<VehicleMakeModel>> apply(TextViewTextChangeEvent textViewTextChangeEvent) throws Exception {
                        return Observable.just(variantlist);
                    }
                })
                .flatMapIterable(new Function<List<VehicleMakeModel>, List<VehicleMakeModel>>() {
                    @Override
                    public List<VehicleMakeModel> apply(List<VehicleMakeModel> v) {
                        return v;
                    }
                })
                .filter(new Predicate<VehicleMakeModel>() {
                    @Override
                    public boolean test(VehicleMakeModel v) {
                        if (searchEdit.getText().toString().isEmpty())
                            return true;
                        else
                            return v.getVariant().toLowerCase().trim().contains(searchEdit.getText().toString().toLowerCase().trim());

                    }
                })
                .map(new Function<VehicleMakeModel, VehicleMakeModel>() {
                    @Override
                    public VehicleMakeModel apply(VehicleMakeModel integer) throws Exception {
                        return integer;

                    }
                })
                .toList()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SingleObserver<List<VehicleMakeModel>>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onSuccess(List<VehicleMakeModel> vehicleMakeModels) {
                        System.out.println("testing");

                    }

                    @Override
                    public void onError(Throwable e) {

                    }
                });

1 个答案:

答案 0 :(得分:0)

关于RxBinding有一个必须记住的事实:事件可观察对象永远不会完成。

RxTextView.textChangeEvents(searchEdit)永远不会调用完整的回调,因此toList()永远不会返回您期望的列表。

这不是错误,而是RxBinding的通缉行为,因为您可以观察到的textChanges永远不会停止监听该事件。