Created
October 21, 2016 13:16
-
-
Save matdziu/8562c57fce16f4dc910655ecc6b394e5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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