本文整理了Java中android.support.v7.widget.SearchView.setQuery()
方法的一些代码示例,展示了SearchView.setQuery()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SearchView.setQuery()
方法的具体详情如下:
包路径:android.support.v7.widget.SearchView
类名称:SearchView
方法名:setQuery
暂无
代码示例来源:origin: aa112901/remusic
@Override
public void onSearch(String t) {
mSearchView.setQuery(t, true);
}
}
代码示例来源:origin: hidroh/materialistic
private void createSearchView(MenuItem menuSearch) {
final SearchView searchView = (SearchView) mActionViewResolver.getActionView(menuSearch);
searchView.setQueryHint(getString(R.string.hint_search_saved_stories));
searchView.setSearchableInfo(((SearchManager) getActivity()
.getSystemService(Context.SEARCH_SERVICE))
.getSearchableInfo(getActivity().getComponentName()));
searchView.setIconified(!mSearchViewExpanded);
searchView.setQuery(mFilter, false);
searchView.setOnSearchClickListener(v -> {
mSearchViewExpanded = true;
v.requestFocus();
});
searchView.setOnCloseListener(() -> {
// trigger a dummy empty search intent, as empty query does not get submitted
searchView.setQuery(FavoriteActivity.EMPTY_QUERY, true);
return false;
});
}
代码示例来源:origin: smuyyh/BookReader
/**
* 展开SearchView进行查询
*
* @param key
*/
private void search(String key) {
MenuItemCompat.expandActionView(searchMenuItem);
if (!TextUtils.isEmpty(key)) {
searchView.setQuery(key, true);
saveSearchHistory(key);
}
}
代码示例来源:origin: pockethub/PocketHub
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.m_search:
searchView.post(() -> searchView.setQuery(lastQuery, false));
return true;
case R.id.m_clear:
RepositorySearchSuggestionsProvider.clear(this);
ToastUtils.show(this, R.string.search_history_cleared);
return true;
case android.R.id.home:
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
代码示例来源:origin: iMeiji/Toutiao
@Override
public void onBackPressed() {
if (suggestionList.getVisibility() != View.GONE) {
// 关闭搜索建议
suggestionList.setVisibility(View.GONE);
hotWordLayout.setVisibility(View.VISIBLE);
} else if (resultLayout.getVisibility() != View.GONE) {
// 关闭搜索结果
searchView.setQuery("", false);
searchView.clearFocus();
resultLayout.setVisibility(View.GONE);
hotWordLayout.setVisibility(View.VISIBLE);
} else {
finish();
}
}
}
代码示例来源:origin: iMeiji/Toutiao
tv.setOnClickListener(view -> {
searchView.clearFocus();
searchView.setQuery(keyWord, true);
});
flexboxLayout.addView(tv);
代码示例来源:origin: pockethub/PocketHub
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.m_search:
searchView.post(() -> searchView.setQuery(lastQuery, false));
return true;
case R.id.m_clear:
IssueSearchSuggestionsProvider.clear(this);
ToastUtils.show(this, R.string.search_history_cleared);
return true;
case android.R.id.home:
Intent intent = RepositoryViewActivity.createIntent(repository);
intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
代码示例来源:origin: hidroh/materialistic
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (mIsMultiPane) {
getMenuInflater().inflate(R.menu.menu_item_compact, menu);
}
if (isSearchable()) {
getMenuInflater().inflate(R.menu.menu_search, menu);
MenuItem menuSearch = menu.findItem(R.id.menu_search);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) mActionViewResolver.getActionView(menuSearch);
searchView.setSearchableInfo(searchManager.getSearchableInfo(
new ComponentName(this, SearchActivity.class)));
searchView.setIconified(true);
searchView.setQuery("", false);
}
return super.onCreateOptionsMenu(menu);
}
代码示例来源:origin: hidroh/materialistic
@Test
public void testSearchView() {
SearchView searchView = (SearchView) actionViewResolver.getActionView(mock(MenuItem.class));
verify(searchView, atLeastOnce()).setOnSearchClickListener(searchViewClickListener.capture());
verify(searchView, atLeastOnce()).setOnCloseListener(searchViewCloseListener.capture());
searchViewClickListener.getAllValues()
.get(searchViewClickListener.getAllValues().size() - 1)
.onClick(searchView);
assertFalse(((FavoriteFragment) fragment).startActionMode(null));
SearchView.OnCloseListener closeListener = searchViewCloseListener.getAllValues()
.get(searchViewCloseListener.getAllValues().size() - 1);
closeListener.onClose();
assertEquals(2, adapter.getItemCount());
((FavoriteFragment) fragment).filter("ask");
verify(favoriteManager, times(2)).attach(observerCaptor.capture(), any());
when(favoriteManager.getSize()).thenReturn(1);
when(favoriteManager.getItem(eq(0))).thenReturn(new TestFavorite(
"2", "http://example.com", "ask HN", System.currentTimeMillis()));
observerCaptor.getValue().onChanged();
assertEquals(1, adapter.getItemCount());
reset(searchView);
closeListener.onClose();
verify(searchView).setQuery(eq(FavoriteActivity.EMPTY_QUERY), eq(true));
}
代码示例来源:origin: iMeiji/Toutiao
String keyWord = suggestionAdapter.getItem(position).getKeyword();
searchView.clearFocus();
searchView.setQuery(keyWord, true);
});
String keyWord = historyAdapter.getItem(position).getKeyWord();
searchView.clearFocus();
searchView.setQuery(keyWord, true);
});
代码示例来源:origin: YoKeyword/IndexableRecyclerView
@Override
public void onBackPressed() {
if (!mSearchFragment.isHidden()) {
// 隐藏 搜索
mSearchView.setQuery(null, false);
getSupportFragmentManager().beginTransaction().hide(mSearchFragment).commit();
return;
}
super.onBackPressed();
}
}
代码示例来源:origin: konradrenner/kolabnotes-android
@Override
public void run() {
mSearchView.setQuery(mSearchKeyWord, true);
}
});
代码示例来源:origin: ABTSoftware/SciChart.Android.Examples
@Override
public void onClick(View v) {
searchResultsDialog.hide();
searchView.setQuery("", false);
}
});
代码示例来源:origin: guanpj/JReadHub
@Override
public boolean onSuggestionClick(int position) {
cursor.moveToPosition(position);
mSearchView.setQuery(cursor.getString(cursor.getColumnIndex("keyWord")), true);
mSearchView.clearFocus();
if (!cursor.isClosed()) {
cursor.close();
}
return true;
}
});
代码示例来源:origin: Odoo-mobile/framework
@Override
public boolean onClose() {
// Restore the SearchView if a query was entered
if (!TextUtils.isEmpty(mSearchView.getQuery())) {
mSearchView.setQuery(null, true);
}
mOnSearchViewChangeListener.onSearchViewClose();
return true;
}
};
代码示例来源:origin: rsiebert/TVHClient
@Override
public boolean onSuggestionClick(int position) {
searchMenuItem.collapseActionView();
// Set the search query and return true so that the onQueryTextSubmit
// is called. This is required to pass additional data to the search activity
Cursor cursor = (Cursor) searchView.getSuggestionsAdapter().getItem(position);
String suggestion = cursor.getString(cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1));
searchView.setQuery(suggestion, true);
return true;
}
代码示例来源:origin: NightscoutFoundation/xDrip
private void pushSearch(String query, boolean submit) {
if (searchItem != null && searchView != null) {
searchItem.expandActionView();
searchView.setQuery(query, submit);
searchView.clearFocus();
} else {
UserError.Log.e(TAG, "SearchView is null!");
}
}
代码示例来源:origin: adityak368/Android-FileBrowser-FilePicker
private void closeSearchView() {
if (mSearchView.isShown()) {
mSearchView.setQuery("", false);
mSearchMenuItem.collapseActionView();
mSearchView.setIconified(true);
}
}
}
代码示例来源:origin: tomahawk-player/tomahawk-android
@Override
public boolean onSuggestionSelect(int position) {
SQLiteCursor cursor = (SQLiteCursor) searchView.getSuggestionsAdapter()
.getItem(position);
int indexColumnSuggestion = cursor
.getColumnIndex(TomahawkSQLiteHelper.SEARCHHISTORY_COLUMN_ENTRY);
searchView.setQuery(cursor.getString(indexColumnSuggestion), false);
return true;
}
代码示例来源:origin: tomahawk-player/tomahawk-android
@Override
public boolean onSuggestionClick(int position) {
SQLiteCursor cursor = (SQLiteCursor) searchView.getSuggestionsAdapter()
.getItem(position);
int indexColumnSuggestion = cursor
.getColumnIndex(TomahawkSQLiteHelper.SEARCHHISTORY_COLUMN_ENTRY);
searchView.setQuery(cursor.getString(indexColumnSuggestion), false);
return true;
}
});
内容来源于网络,如有侵权,请联系作者删除!