我RxSearchView
用来以“键入时搜索”的形式查询文本更改
RxSearchView.queryTextChanges(searchView)
但我也想在用户提交搜索时捕捉到,所以我必须使用
RxSearchView.queryTextChangeEvents(searchView)
或者searchView.setOnQueryTextListener
当我使用最后两个中的任何一个时,看起来他们正在取消第一个RxSearchView.queryTextChanges
,看起来只能有 1 个可观察对象附加到 SearchView。
如何同时观察这两个事件?
这是完整的代码
private void setupSearch() {
RxSearchView.queryTextChangeEvents(searchView)
.skip(1)
.throttleLast(100, TimeUnit.MILLISECONDS)
.debounce(200, TimeUnit.MILLISECONDS)
.onBackpressureLatest()
.observeOn(AndroidSchedulers.mainThread())
.filter(new Func1<SearchViewQueryTextEvent, Boolean>() {
@Override
public Boolean call(SearchViewQueryTextEvent searchViewQueryTextEvent) {
final boolean empty = TextUtils.isEmpty(searchViewQueryTextEvent.queryText());
if (empty) {
//Dont show anything clear adapter
}
return !empty;
}
}).subscribe(new Subscriber<SearchViewQueryTextEvent>() {
@Override
public void onNext(SearchViewQueryTextEvent searchViewQueryTextEvent) {
String searchTerm = searchViewQueryTextEvent.queryText().toString();
if (searchViewQueryTextEvent.isSubmitted()) {
submitFullSearch(searchTerm);
} else {
submitRecommendationsSearch(searchTerm);
}
}
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
});
}