0

In RxJava1 you can create a debouncer this way

RxSearchView.queryTextChanges(searchView)
    .debounce(1, TimeUnit.SECONDS) // stream will go down after 1 second inactivity of user
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(new Consumer<CharSequence>() {
        @Override
        public void accept(@NonNull CharSequence charSequence) throws Exception {
            // perform necessary operation with `charSequence`
        }
    });

According to Wait until the user stops typing before executing a heavy search in searchview

But I can't figure out how to create it in RxJava2

enter image description here

WHOATEMYNOODLES
  • 845
  • 9
  • 25
  • 1
    RxJava 2 uses the `io.reactivex.Observable` as the type and `io.reactivex.functions.Consumer` for that `subscribe` overload. Please check that you have the right types with `queryTextChanges`. – akarnokd Sep 05 '19 at 10:57

1 Answers1

0

remove

import io.reactivex.functions.Consumer;

add

import java.util.function.Consumer;

RxSearchView.queryTextChanges(searchView)
    .debounce(1, TimeUnit.SECONDS) // stream will go down after 1 second inactivity of user
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(result -> new Consumer<CharSequence>() {
                @Override
                public void accept(CharSequence charSequence) {
                    // use result
                }
            });
JakeB
  • 2,043
  • 3
  • 12
  • 19