I use the usual TextWathcer to collect Flowable like this

 private Flowable<String> createTextChangeFlowable() { Flowable<String> flowable = Flowable.create(iEmitter -> { TextWatcher textWatcher = new TextWatcher() { @Override public void beforeTextChanged(final CharSequence iCharSequence, final int iI, final int iI1, final int iI2) { isNoResultVisable(false); } @Override public void onTextChanged(final CharSequence iCharSequence, final int iI, final int iI1, final int iI2) { iEmitter.onNext(iCharSequence.toString()); } @Override public void afterTextChanged(final Editable iEditable) { if (iEditable.toString().isEmpty()) { mAdapter.realizeSettlementList(); } } }; mInput.addTextChangedListener(textWatcher); iEmitter.setCancellable(() -> mInput.removeTextChangedListener(textWatcher)); }, BackpressureStrategy.BUFFER); return flowable.filter(iS -> !iS.isEmpty()).debounce(500, TimeUnit.MILLISECONDS); } 

And in onStart() subscribe to it.

 @Override protected void onStart() { super.onStart(); Flowable<String> flowable = createTextChangeFlowable(); mDisposable = mPresenter.doOnQuerySearch(flowable); } 

Like this

 public Disposable doOnQuerySearch(Flowable<String> iFlowable) { return iFlowable.subscribeOn(Schedulers.single())// .observeOn(AndroidSchedulers.mainThread())// .doOnNext(iConsumer -> mListener.realizeSettlementList())// .doOnNext(iConsumer -> mListener.setProgressBar(true))// .observeOn(Schedulers.single())// .map(iQuery -> mSearchEngine.search(iQuery))// .observeOn(AndroidSchedulers.mainThread())// .subscribe(// iFilteredList -> { mListener.setProgressBar(false); mListener.setFilteredList(iFilteredList); }// ); } 

Now, what happens when the user enters a letter, makes a selection and shows the result

If we enter the second and the letter, then again the same thing.

Now, when I delete one letter, one more remains and according to the condition the selection occurs again, when I delete the last letter, then afterTextChanged() the condition is triggered

 if (iEditable.toString().isEmpty()) { mAdapter.realizeSettlementList(); } 

and the sample is cleared.

It is interesting when I enter (for example) 2 letters the result is shown, and then I delete them not with a delay, one at a time, but immediately press the button 2 times to erase, then for some reason I emit the last letter ... and I receive a sample by the last letter, although in fact there is nothing in the input field.

How is the last letter maintained and emitted during a quick removal? Why this effect does not exist when I delete one after another, one after another, waiting for the result ...

What am I doing wrong?

  • one
    I understand that the question is likely to understand, but . - post_zeew
  • @post_zeew Well, sort of understand, too ... But in general, I don’t need this behavior, when there is nothing in the input field, and the sample is shown ... As it’s not logical to go - Aleksey Timoshchenko
  • I can be wrong, but in my opinion the filter (iS ->! IS.isEmpty ()) spoils everything. Those. the empty string will never be issued and the list is not cleared, it remains the last result for a non-empty emith. - Yura Ivanov
  • @YuraIvanov is not, without her everything is exactly the same - Aleksey Timoshchenko February

0