Skip to content

Instantly share code, notes, and snippets.

@amitshekhariitbhu
Created October 15, 2017 17:51
Show Gist options
  • Save amitshekhariitbhu/b50148fbdd73b1d822fe06270130175e to your computer and use it in GitHub Desktop.
Save amitshekhariitbhu/b50148fbdd73b1d822fe06270130175e to your computer and use it in GitHub Desktop.
public class RxSearchObservable {
public static Observable<String> fromView(SearchView searchView) {
final PublishSubject<String> subject = PublishSubject.create();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
subject.onComplete();
return true;
}
@Override
public boolean onQueryTextChange(String text) {
subject.onNext(text);
return true;
}
});
return subject;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment