Skip to content

Instantly share code, notes, and snippets.

@amitshekhariitbhu
Last active October 16, 2017 11:46
Show Gist options
  • Save amitshekhariitbhu/6616b3f96514ae7b8251590d3fb7e10f to your computer and use it in GitHub Desktop.
Save amitshekhariitbhu/6616b3f96514ae7b8251590d3fb7e10f to your computer and use it in GitHub Desktop.
RxSearchObservable.fromView(searchView)
.debounce(300, TimeUnit.MILLISECONDS)
.filter(new Predicate<String>() {
@Override
public boolean test(String text) throws Exception {
if (text.isEmpty()) {
return false;
} else {
return true;
}
}
})
.distinctUntilChanged()
.switchMap(new Function<String, ObservableSource<String>>() {
@Override
public ObservableSource<String> apply(String query) throws Exception {
return dataFromNetwork(query);
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<String>() {
@Override
public void accept(String result) throws Exception {
textViewResult.setText(result);
}
});
@rezaiyan
Copy link

Thanks. can you use this code in sample project?
I'm confused to use this with auto completeble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment