Skip to content

Instantly share code, notes, and snippets.

@matdziu
Created October 21, 2016 13:16
Show Gist options
  • Save matdziu/8562c57fce16f4dc910655ecc6b394e5 to your computer and use it in GitHub Desktop.
Save matdziu/8562c57fce16f4dc910655ecc6b394e5 to your computer and use it in GitHub Desktop.
public class RxSearch {
public static Observable<String> fromSearchView(@NonNull final SearchView searchView) {
final BehaviorSubject<String> subject = BehaviorSubject.create("");
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
subject.onCompleted();
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
if (!newText.isEmpty()) {
subject.onNext(newText);
}
return true;
}
});
return subject;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment