JakeWharton / RxBinding

RxJava binding APIs for Android's UI widgets.
Apache License 2.0
9.68k stars 971 forks source link

RxTextView.textChanges will not emiit text changes once onError method is run #272

Closed peng0398 closed 8 years ago

peng0398 commented 8 years ago

Just like the code below , using RxTextView.textChanges for a search function ,once the text changed, I do a lot of other works ,the progress may produce error ,when onError is run , the textChanges will not emiit text changes .

RxTextView.textChanges(et_keyword)
                .subscribeOn(AndroidSchedulers.mainThread())
                .debounce(600, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
                .filter(new Func1<CharSequence, Boolean>() {
                    @Override
                    public Boolean call(CharSequence charSequence) {
                        tv_result.setText("");
                        return charSequence.length() > 0;
                    }
                })
                .observeOn(Schedulers.io())
                .switchMap(new Func1<CharSequence, Observable<Data>>() {
                    @Override
                    public Observable<Data> call(CharSequence charSequence) {
                        return service.searchProdcut("utf-8", charSequence.toString());
                    }
                })
                .map(new Func1<Data, ArrayList<ArrayList<String>>>() {
                    @Override
                    public ArrayList<ArrayList<String>> call(Data data) {
                        return data.result;
                    }
                })
                .flatMap(new Func1<ArrayList<ArrayList<String>>, Observable<ArrayList<String>>>() {
                    @Override
                    public Observable<ArrayList<String>> call(ArrayList<ArrayList<String>> arrayLists) {
                        return Observable.from(arrayLists);
                    }
                })
                .filter(new Func1<ArrayList<String>, Boolean>() {
                    @Override
                    public Boolean call(ArrayList<String> strings) {
                        return strings.size() >= 2;
                    }
                })
                .map(new Func1<ArrayList<String>, String>() {
                    @Override
                    public String call(ArrayList<String> strings) {
                        return "[name:" + strings.get(0) + ", ID:" + strings.get(1) + "]\n";
                    }
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<String>() {
                    @Override
                    public void call(String charSequence) {
                        showpop(charSequence);
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        // Handle Error
                        throwable.printStackTrace();
                    }
                });
JakeWharton commented 8 years ago

This is the Rx contract. If you need a stream to continue then ensure it doesn't error or re-subscribe upstream on each error.

On Tue, Jul 26, 2016, 2:37 AM Bob.Peng notifications@github.com wrote:

RxTextView.textChanges(et_keyword) .subscribeOn(AndroidSchedulers.mainThread()) .debounce(600, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread()) .filter(new Func1() { @Override https://github.com/Override public Boolean call(CharSequence charSequence) { tv_result.setText(""); return charSequence.length() > 0; } }) .observeOn(Schedulers.io()) .switchMap(new Func1>() { @Override https://github.com/Override public Observable call(CharSequence charSequence) { return service.searchProdcut("utf-8", charSequence.toString()); } }) .map(new Func1>>() { @Override https://github.com/Override public ArrayList> call(Data data) { return data.result; } }) .flatMap(new Func1>, Observable>>() { @Override https://github.com/Override public Observable> call(ArrayList> arrayLists) { return Observable.from(arrayLists); } }) .filter(new Func1, Boolean>() { @Override https://github.com/Override public Boolean call(ArrayList strings) { return strings.size() >= 2; } }) .map(new Func1, String>() { @Override https://github.com/Override public String call(ArrayList strings) { return "[name:" + strings.get(0) + ", ID:" + strings.get(1) + "]\n"; } }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1() { @Override https://github.com/Override public void call(String charSequence) { showpop(charSequence); } }, new Action1() { @Override https://github.com/Override public void call(Throwable throwable) { // Handle Error throwable.printStackTrace(); } });

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/JakeWharton/RxBinding/issues/272, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEZBkqfh6w_UThUkWsoIaSQTO3nyLks5qZatDgaJpZM4JU1Ik .