0

I have RxSearchView:

RxSearchView.queryTextChanges(searchView)
            .filter(charSequence -> !TextUtils.isEmpty(charSequence))
            .debounce(600, TimeUnit.MILLISECONDS)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(query -> {
                Toast.makeText(this, query, Toast.LENGTH_SHORT).show();
            });

When I search word test the Toast shows me test, after that I would like to clean searching text using backspace, and the problem is when the search is empty in the Toast appears with text t.

How to solve this problem ?

I was trying to use .filter(item -> item.length() > 1) but this doesn't work too, in that case Toast appears with text te

enter image description here

azizbekian
  • 60,783
  • 13
  • 169
  • 249
VLeonovs
  • 2,193
  • 5
  • 24
  • 44

1 Answers1

0

The problem was in sequence. debounce must be before filter

This will work:

RxSearchView.queryTextChanges(searchView)
            .debounce(600, TimeUnit.MILLISECONDS)
            .filter(charSequence -> !TextUtils.isEmpty(charSequence))
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(query -> {
                Toast.makeText(this, query, Toast.LENGTH_SHORT).show();
            });
VLeonovs
  • 2,193
  • 5
  • 24
  • 44