Last active
October 16, 2017 11:46
-
-
Save amitshekhariitbhu/6616b3f96514ae7b8251590d3fb7e10f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. can you use this code in sample project?
I'm confused to use this with auto completeble.