Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1.     public static Observable<String> getSearchObservable(SearchView searchView) {
  2.         return Observable.<String>create(publisher -> {
  3.             final SearchView.OnQueryTextListener listener = new SearchView.OnQueryTextListener() {
  4.                 @Override
  5.                 public boolean onQueryTextSubmit(String query) {
  6.                     publisher.onNext(query);
  7.                     return true;
  8.                 }
  9.  
  10.                 @Override
  11.                 public boolean onQueryTextChange(String newText) {
  12.                     publisher.onNext(newText);
  13.                     return true;
  14.                 }
  15.             };
  16.             searchView.setOnQueryTextListener(listener);
  17.             publisher.setCancellable(() -> searchView.setOnQueryTextListener(null));
  18.         }).skip(1);
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement