List of usage examples for android.widget SearchView setOnSuggestionListener
public void setOnSuggestionListener(OnSuggestionListener listener)
From source file:net.abcdroid.devfest12.ui.SearchActivity.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void setupSearchMenuItem(Menu menu) { final MenuItem searchItem = menu.findItem(R.id.menu_search); if (searchItem != null && UIUtils.hasHoneycomb()) { SearchView searchView = (SearchView) searchItem.getActionView(); if (searchView != null) { SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override/* w ww .jav a 2s . c o m*/ public boolean onQueryTextSubmit(String s) { ReflectionUtils.tryInvoke(searchItem, "collapseActionView"); return false; } @Override public boolean onQueryTextChange(String s) { return false; } }); searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionSelect(int i) { return false; } @Override public boolean onSuggestionClick(int i) { ReflectionUtils.tryInvoke(searchItem, "collapseActionView"); return false; } }); } } }
From source file:com.conferenceengineer.android.iosched.ui.SearchActivity.java
@Override @TargetApi(Build.VERSION_CODES.HONEYCOMB) public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.search, menu); final MenuItem searchItem = menu.findItem(R.id.menu_search); if (searchItem != null && UIUtils.hasHoneycomb()) { SearchView searchView = (SearchView) searchItem.getActionView(); if (searchView != null) { SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setQueryRefinementEnabled(true); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override/*w w w . j a v a 2 s. c o m*/ public boolean onQueryTextSubmit(String s) { ReflectionUtils.tryInvoke(searchItem, "collapseActionView"); return false; } @Override public boolean onQueryTextChange(String s) { return false; } }); searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionSelect(int i) { return false; } @Override public boolean onSuggestionClick(int i) { ReflectionUtils.tryInvoke(searchItem, "collapseActionView"); return false; } }); } } return true; }
From source file:com.gm.goldencity.fragment.search.SearchFragment.java
private void doSearch(SearchView searchView) { RxSearchView.queryTextChangeEvents(searchView).skip(1) .doOnNext(charSequence -> GLog.e("Search", "Searching: " + charSequence)) .throttleLast(100, TimeUnit.MILLISECONDS).debounce(300, TimeUnit.MILLISECONDS) // .onBackpressureLatest() .observeOn(scheduler.mainThread()).filter(searchViewQueryTextEvent -> { final boolean empty = TextUtils.isEmpty(searchViewQueryTextEvent.queryText()); if (empty) { GLog.e("Search", "empty view"); clearAdapter();/*w w w . j a v a2s . co m*/ } return !empty; }).switchMap(searchViewQueryTextEvent -> { GLog.e("Search", "requesting " + searchViewQueryTextEvent.queryText().toString()); String searchTerm = searchViewQueryTextEvent.queryText().toString(); boolean submitted = searchViewQueryTextEvent.isSubmitted(); //Show Loading and Hide RecyclerView Observable<SearchResults> observable; if (submitted) { observable = presenter.fullSearch(searchTerm); } else { if (TextUtils.isEmpty(searchTerm)) { clearResults(); } observable = presenter.searchSuggestion(searchTerm); } //Hide Loading and show RecyclerView return observable.compose(scheduler.normalSchedulers()).doOnComplete(this::showContent); }).doOnNext(charSequence -> GLog.e("Search", "got data")) .subscribe(this::showSearchResponse, throwable -> { throwable.printStackTrace(); showEmptyErrorView(throwable.getMessage()); }); searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionSelect(int position) { return true; } @Override public boolean onSuggestionClick(int position) { return true; } }); }