Java Code Examples for android.support.v7.widget.SearchView#setQuery()
The following examples show how to use
android.support.v7.widget.SearchView#setQuery() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SearchActivity.java From OpenHub with GNU General Public License v3.0 | 5 votes |
@Override public boolean onPrepareOptionsMenu(Menu menu) { if (isInputMode) { menu.findItem(R.id.action_info).setVisible(false); menu.findItem(R.id.action_sort).setVisible(false); SearchView searchView = (SearchView) MenuItemCompat. getActionView(menu.findItem(R.id.action_search)); searchView.setQuery(mPresenter.getSearchModels().get(0).getQuery(), false); } else { menu.findItem(R.id.action_info).setVisible(false); menu.findItem(R.id.action_sort).setVisible(pagerAdapter.getCount() != 0); } return super.onPrepareOptionsMenu(menu); }
Example 2
Source File: BaseActivityTest.java From open with GNU General Public License v3.0 | 5 votes |
@Test public void onDestroy_shouldSaveCurrentSearchTerm() throws Exception { activity.searchMenuItem.expandActionView(); SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); searchView.setQuery("query", false); activity.onDestroy(); assertThat(app.getCurrentSearchTerm()).isEqualTo("query"); }
Example 3
Source File: BaseActivity.java From open with GNU General Public License v3.0 | 5 votes |
private void restoreCurrentSearchTerm() { final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem); if (app.getCurrentSearchTerm() != null) { searchMenuItem.expandActionView(); searchView.setQuery(app.getCurrentSearchTerm(), false); } }
Example 4
Source File: BaseActivity.java From open with GNU General Public License v3.0 | 5 votes |
private void handleMapsIntent(SearchView searchView, Uri data) { if (data.toString().contains("q=")) { searchMenuItem.expandActionView(); String queryString = Uri.decode(data.toString().split("q=")[1].split("@")[0]); searchView.setQuery(queryString, true); } }
Example 5
Source File: BaseActivity.java From open with GNU General Public License v3.0 | 5 votes |
private void handleGeoIntent(SearchView searchView, Uri data) { if (data.toString().contains("q=")) { searchMenuItem.expandActionView(); String queryString = Uri.decode(data.toString().split("q=")[1]); searchView.setQuery(queryString, true); } }
Example 6
Source File: BaseActivity.java From open with GNU General Public License v3.0 | 5 votes |
private void resetSearchView() { final SearchView searchView = (SearchView) searchMenuItem.getActionView(); searchView.setQuery("", false); searchView.clearFocus(); searchView.setIconified(true); autoCompleteAdapter.resetCursor(); autoCompleteAdapter.loadSavedSearches(); }
Example 7
Source File: OrdersFragment.java From Woodmin with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { //menu.clear(); super.onCreateOptionsMenu(menu,inflater); inflater.inflate(R.menu.order_fragment_menu, menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); if (searchView != null) { List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch(); SearchableInfo info = searchManager.getSearchableInfo(getActivity().getComponentName()); for (SearchableInfo inf : searchables) { if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) { info = inf; } } searchView.setSearchableInfo(info); searchView.setOnQueryTextListener(this); searchView.setQueryHint(getActivity().getString(R.string.order_title_search)); if(mQuery != null && mQuery.length() > 0) { searchView.setQuery(mQuery, true); searchView.setIconifiedByDefault(false); searchView.performClick(); searchView.requestFocus(); } else { searchView.setIconifiedByDefault(true); } } }
Example 8
Source File: CustomersFragment.java From Woodmin with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { //menu.clear(); super.onCreateOptionsMenu(menu,inflater); inflater.inflate(R.menu.customer_fragment_menu, menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); if (searchView != null) { List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch(); SearchableInfo info = searchManager.getSearchableInfo(getActivity().getComponentName()); for (SearchableInfo inf : searchables) { if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) { info = inf; } } searchView.setSearchableInfo(info); searchView.setOnQueryTextListener(this); searchView.setQueryHint(getActivity().getString(R.string.customer_title_search)); if(mQuery != null && mQuery.length() > 0) { searchView.setQuery(mQuery, true); searchView.setIconifiedByDefault(false); searchView.performClick(); searchView.requestFocus(); } else { searchView.setIconifiedByDefault(true); } } }
Example 9
Source File: ProductsFragment.java From Woodmin with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { //menu.clear(); super.onCreateOptionsMenu(menu,inflater); inflater.inflate(R.menu.product_fragment_menu, menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); if (searchView != null) { List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch(); SearchableInfo info = searchManager.getSearchableInfo(getActivity().getComponentName()); for (SearchableInfo inf : searchables) { if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) { info = inf; } } searchView.setSearchableInfo(info); searchView.setOnQueryTextListener(this); searchView.setQueryHint(getActivity().getString(R.string.product_title_search)); if(mQuery != null && mQuery.length() > 0) { searchView.setQuery(mQuery, true); searchView.setIconifiedByDefault(false); searchView.performClick(); searchView.requestFocus(); } else { searchView.setIconifiedByDefault(true); } } }
Example 10
Source File: TriggersFragment.java From hawkular-android-client with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { super.onCreateOptionsMenu(menu, menuInflater); menuInflater.inflate(R.menu.menu_search, menu); MenuItem item = menu.findItem(R.id.menu_search1); searchView = (SearchView) MenuItemCompat.getActionView(item); searchView.setOnQueryTextListener(this); if (searchText != null) { searchView.setQuery(searchText, false); } }
Example 11
Source File: FavMetricsFragment.java From hawkular-android-client with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { super.onCreateOptionsMenu(menu, menuInflater); menuInflater.inflate(R.menu.menu_search, menu); MenuItem item = menu.findItem(R.id.menu_search1); searchView = (SearchView) MenuItemCompat.getActionView(item); searchView.setOnQueryTextListener(this); if (searchText != null) { searchView.setQuery(searchText, false); } }
Example 12
Source File: AlertsFragment.java From hawkular-android-client with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { super.onCreateOptionsMenu(menu, menuInflater); menuInflater.inflate(R.menu.menu_search, menu); menuInflater.inflate(R.menu.toolbar_alerts, menu); MenuItem item = menu.findItem(R.id.menu_search1); searchView = (SearchView) MenuItemCompat.getActionView(item); searchView.setOnQueryTextListener(this); if (searchText != null) { searchView.setQuery(searchText, false); } }
Example 13
Source File: OrdersFragment.java From Woodmin with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { //menu.clear(); super.onCreateOptionsMenu(menu,inflater); inflater.inflate(R.menu.order_fragment_menu, menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); if (searchView != null) { List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch(); SearchableInfo info = searchManager.getSearchableInfo(getActivity().getComponentName()); for (SearchableInfo inf : searchables) { if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) { info = inf; } } searchView.setSearchableInfo(info); searchView.setOnQueryTextListener(this); searchView.setQueryHint(getActivity().getString(R.string.order_title_search)); if(mQuery != null && mQuery.length() > 0) { searchView.setQuery(mQuery, true); searchView.setIconifiedByDefault(false); searchView.performClick(); searchView.requestFocus(); } else { searchView.setIconifiedByDefault(true); } } }
Example 14
Source File: CustomersFragment.java From Woodmin with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { //menu.clear(); super.onCreateOptionsMenu(menu,inflater); inflater.inflate(R.menu.customer_fragment_menu, menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); if (searchView != null) { List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch(); SearchableInfo info = searchManager.getSearchableInfo(getActivity().getComponentName()); for (SearchableInfo inf : searchables) { if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) { info = inf; } } searchView.setSearchableInfo(info); searchView.setOnQueryTextListener(this); searchView.setQueryHint(getActivity().getString(R.string.customer_title_search)); if(mQuery != null && mQuery.length() > 0) { searchView.setQuery(mQuery, true); searchView.setIconifiedByDefault(false); searchView.performClick(); searchView.requestFocus(); } else { searchView.setIconifiedByDefault(true); } } }
Example 15
Source File: ProductsFragment.java From Woodmin with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { //menu.clear(); super.onCreateOptionsMenu(menu,inflater); inflater.inflate(R.menu.product_fragment_menu, menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); if (searchView != null) { List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch(); SearchableInfo info = searchManager.getSearchableInfo(getActivity().getComponentName()); for (SearchableInfo inf : searchables) { if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) { info = inf; } } searchView.setSearchableInfo(info); searchView.setOnQueryTextListener(this); searchView.setQueryHint(getActivity().getString(R.string.product_title_search)); if(mQuery != null && mQuery.length() > 0) { searchView.setQuery(mQuery, true); searchView.setIconifiedByDefault(false); searchView.performClick(); searchView.requestFocus(); } else { searchView.setIconifiedByDefault(true); } } }
Example 16
Source File: Food_RecyclerView_Main.java From Stayfit with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_actionview, menu); super.onCreateOptionsMenu(menu, inflater); final SearchView search = (SearchView) menu.findItem(R.id.action_search).getActionView(); if (search != null) { search.setIconifiedByDefault(true); search.setQuery(voice_query, true); // search.setQueryHint(voice_query); search.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { String food; /*if (voice_query != "") { food = voice_query; search.setQueryHint(voice_query); Log.d("searchvoice",voice_query); } else*/ food = query; food = food.replace(" ", ""); //String f_url = "https://api.nutritionix.com/v1_1/search/"+food+"?results=0%3A20&cal_min=0&cal_max=50000&fields=item_name%2Cbrand_name%2Citem_id%2Cbrand_id&appId=42e8cbe9&appKey=a4e373fe0f10ab1de40cffbffb9db544"; String f_url = "https://api.nutritionix.com/v1_1/search/" + food + "?results=0%3A20&cal_min=0&cal_max=50000&fields=item_name%2Cbrand_name%2Citem_id%2Cbrand_id%2Citem_description%2Cnf_protein%2Cnf_calories%2Cnf_total_carbohydrate%2Cnf_total_fat&appId=42e8cbe9&appKey=a4e373fe0f10ab1de40cffbffb9db544"; MyDownloadJsonAsyncTask downloadJson = new MyDownloadJsonAsyncTask(mRecyclerViewAdapter); Log.d("RahulMaddineni", f_url); downloadJson.execute(f_url); return true; } @Override public boolean onQueryTextChange(String newText) { return true; } }); } super.onCreateOptionsMenu(menu, inflater); }
Example 17
Source File: SearchActivity.java From OpenHub with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_search, menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); searchView.setOnQueryTextListener(this); searchView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS); searchView.setQuery(mPresenter.getSearchModels().get(0).getQuery(), false); if (isInputMode) { MenuItemCompat.expandActionView(searchItem); } else { MenuItemCompat.collapseActionView(searchItem); } MenuItemCompat.setOnActionExpandListener(searchItem, this); AutoCompleteTextView autoCompleteTextView = searchView .findViewById(android.support.v7.appcompat.R.id.search_src_text); autoCompleteTextView.setThreshold(0); autoCompleteTextView.setAdapter(new ArrayAdapter<>(this, R.layout.layout_item_simple_list, mPresenter.getSearchRecordList())); autoCompleteTextView.setDropDownBackgroundDrawable(new ColorDrawable(ViewUtils.getWindowBackground(getActivity()))); autoCompleteTextView.setOnItemClickListener((parent, view, position, id) -> { onQueryTextSubmit(parent.getAdapter().getItem(position).toString()); }); return super.onCreateOptionsMenu(menu); }
Example 18
Source File: SearchActivity.java From ratebeer with GNU General Public License v3.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); searchEdit = (SearchView) findViewById(R.id.search_text); TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs); resultsPager = (ViewPager) findViewById(R.id.results_pager); loadingProgress = (ProgressBar) findViewById(R.id.loading_progress); emptyText = (TextView) findViewById(R.id.empty_text); setupDefaultUpButton(); modeBeerPicker = getIntent().getBooleanExtra("modeBeerPicker", false); // Set up tabs searchEdit.setQuery(getIntent().getStringExtra("query"), false); searchEdit.setInputType(InputType.TYPE_CLASS_TEXT); tabTypes = new ArrayList<>(3); tabs = new ArrayList<>(3); tabsTitles = new ArrayList<>(3); addTab(TAB_BEERS, R.string.search_beers); if (!modeBeerPicker) { addTab(TAB_BREWERIES, R.string.search_breweries); addTab(TAB_PLACES, R.string.search_places); } RxViewPager.pageSelected(resultsPager).subscribe(this::refreshTab); resultsPager.setAdapter(new SearchPagerAdapter()); tabLayout.setupWithViewPager(resultsPager); if (tabs.size() == 1) tabLayout.setVisibility(View.GONE); refreshTab(0); // When in picker mode, only search beers and set the activity result as cancelled until we actually picked a beer if (modeBeerPicker) { setResult(RESULT_CANCELED); if (TextUtils.isEmpty(searchEdit.getQuery())) { // No query given so focus on search field and do not show loading spinner until an input is given loadingProgress.setVisibility(View.INVISIBLE); searchEdit.requestFocus(); } } }
Example 19
Source File: GlobalSearchFragment.java From Android-Remote with GNU General Public License v3.0 | 4 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.clear(); inflater.inflate(R.menu.global_search_menu, menu); // Create a listener for search change final MenuItem search = menu.findItem(R.id.global_search_menu_search); final SearchView searchView = (SearchView) search.getActionView(); searchView.setIconifiedByDefault(true); searchView.setIconified(false); final SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextChange(String newText) { return false; } @Override public boolean onQueryTextSubmit(String query) { mSwipeRefreshLayout.setRefreshing(true); mEmptyView.setRefreshing(true); Message msg = Message.obtain(); msg.obj = ClementineMessageFactory.buildGlobalSearch(query); App.ClementineConnection.mHandler.sendMessage(msg); hideSoftInput(); // Set the actionbar title mActionBar.setTitle(getResources().getString(R.string.global_search_query, query)); mActionBar.setSubtitle("/"); // Query must be empty in order to collapse the search view. searchView.setQuery("", false); searchView.setIconified(true); // Remove currently present adapters mAdapters.clear(); showList(); return true; } }; searchView.setOnQueryTextListener(queryTextListener); searchView.setQueryHint(getString(R.string.global_search_search)); EditText searchText = (EditText) searchView.findViewById( android.support.v7.appcompat.R.id.search_src_text); searchText.setHintTextColor(ContextCompat.getColor(getActivity(), R.color.searchview_edittext_hint)); super.onCreateOptionsMenu(menu, inflater); }
Example 20
Source File: SearchActivity.java From CrimeTalk-Reader with Apache License 2.0 | 2 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_search, menu); // Modify some aspects of the SearchView final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); final MenuItem searchItem = menu.findItem(R.id.action_search); final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setQuery(mQuery, false); searchView.setIconified(false); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String s) { return false; } @Override public boolean onQueryTextChange(String query) { SearchActivity.this.mQuery = query; return false; } }); final SearchView.SearchAutoComplete searchAutoComplete = (SearchView.SearchAutoComplete) searchView.findViewById(R.id.search_src_text); searchAutoComplete.setTextColor(getResources().getColor(R.color.white)); // Recovering from orientation change, try not to have focus if (mQuery != null && !mQuery.isEmpty()) { searchView.clearFocus(); } return true; }