List of usage examples for android.widget SearchView setSearchableInfo
public void setSearchableInfo(SearchableInfo searchable)
From source file:com.timemachine.controller.ControllerActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu items for use in the action bar MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_activity_actions, menu); // Associate searchable configuration with the SearchView // Get the SearchView and set the searchable configuration SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); // Change the text color in the search view int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null); searchTextView = (TextView) searchView.findViewById(id); searchTextView.setHintTextColor(Color.parseColor("#80ffffff")); searchTextView.setTextColor(Color.parseColor("#ffffff")); return super.onCreateOptionsMenu(menu); }
From source file:mroza.forms.ChooseProgramActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { this.menu = menu; getMenuInflater().inflate(R.menu.choose_program_menu, menu); //Associate programs_searchable configuration with the SearchView SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); android.support.v7.widget.SearchView searchView = (android.support.v7.widget.SearchView) menu .findItem(R.id.action_search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); EditText searchPlate = (EditText) searchView .findViewById(android.support.v7.appcompat.R.id.search_src_text); searchPlate.setImeOptions(EditorInfo.IME_ACTION_SEARCH); searchPlate.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override/* www . ja va2s. co m*/ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { //On search or enter clicked if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_NULL) { if (v.getText().toString().equals("")) { refreshChildTableList(); clearSearchField(); clearFilters(true); enableShowAllButton(false); } } return false; } }); restoreSavedFilters(); return true; }
From source file:de.tap.easy_xkcd.Activities.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); // Get the SearchView and set the searchable configuration SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); final SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(false); searchMenuItem = menu.findItem(R.id.action_search); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override//from www.j ava 2s . co m public boolean onQueryTextSubmit(String query) { MenuItem searchMenuItem = getSearchMenuItem(); searchMenuItem.collapseActionView(); searchView.setQuery("", false); //Hide Keyboard View view = MainActivity.this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } return false; } @Override public boolean onQueryTextChange(String newText) { return false; } }); MenuItemCompat.setOnActionExpandListener(searchMenuItem, new MenuItemCompat.OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem item) { View view = getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(view, 0); } searchView.requestFocus(); return true; } @Override public boolean onMenuItemActionCollapse(MenuItem item) { View view = getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } return true; } }); if (prefHelper.hideDonate()) menu.findItem(R.id.action_donate).setVisible(false); return true; }
From source file:net.mypapit.mobile.myrepeater.RepeaterListActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.display_map, menu); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(false); searchView.setQueryHint("part of repeater callsign"); SearchView.OnQueryTextListener textChangeListener = new SearchView.OnQueryTextListener() { @Override/*from w ww .j a v a 2 s . com*/ public boolean onQueryTextSubmit(String searchText) { adapter.getFilter().filter(searchText); Log.d("MYRepeater", "search: " + searchText); adapter.notifyDataSetChanged(); return true; } @Override public boolean onQueryTextChange(String searchText) { // TODO Auto-generated method stub adapter.getFilter().filter(searchText); adapter.notifyDataSetChanged(); return true; } }; searchView.setOnQueryTextListener(textChangeListener); } return super.onCreateOptionsMenu(menu); }
From source file:at.ac.tuwien.detlef.activities.MainActivity.java
/** * Get the {@link SearchView} and set the {@link SearchableInfo} * configuration for the {@link EpisodeListFragment#getFilter() episode * keyword filter}./*from w w w . j av a 2 s. co m*/ */ private void setSearchManager() { String tmptag = "searchmanager"; Log.d(tmptag, "setSearchManager()"); if (menu.findItem(R.id.menu_search) == null) { Log.d(tmptag, "is null"); return; } SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(true); searchView.setOnQueryTextListener(new EpisodeSearchQueryTextListener(getEpisodeListFragment())); }
From source file:com.jackleeentertainment.oq.ui.layout.fragment.ContactsListFragment.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override/*from ww w . j a va 2s.c o m*/ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { // Inflate the menu items inflater.inflate(R.menu.contact_list_menu, menu); // Locate the search item MenuItem searchItem = menu.findItem(R.id.menu_search); // In version 3.0 and later, sets up and configures the ActionBar SearchView if (Utils.hasHoneycomb()) { // Retrieves the system search manager service final SearchManager searchManager = (SearchManager) getActivity() .getSystemService(Context.SEARCH_SERVICE); // Retrieves the SearchView from the search menu item final SearchView searchView = (SearchView) searchItem.getActionView(); // Assign searchable info to SearchView searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName())); // Set listeners for SearchView searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String queryText) { // Nothing needs to happen when the user submits the search string return true; } @Override public boolean onQueryTextChange(String newText) { // Called when the action bar search text has changed. Updates // the search filter, and restarts the loader to do a new query // using the new search string. String newFilter = !TextUtils.isEmpty(newText) ? newText : null; // Don't do anything if the filter is empty if (mSearchTerm == null && newFilter == null) { return true; } // Don't do anything if the new filter is the same as the current filter if (mSearchTerm != null && mSearchTerm.equals(newFilter)) { return true; } // Updates current filter to new filter mSearchTerm = newFilter; // Restarts the loader. This triggers onCreateLoader(), which builds the // necessary content Uri from mSearchTerm. mSearchQueryChanged = true; getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this); return true; } }); if (Utils.hasICS()) { // This listener added in ICS searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem menuItem) { // Nothing to do when the action item is expanded return true; } @Override public boolean onMenuItemActionCollapse(MenuItem menuItem) { // When the user collapses the SearchView the current search string is // cleared and the loader restarted. if (!TextUtils.isEmpty(mSearchTerm)) { onSelectionCleared(); } mSearchTerm = null; getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this); return true; } }); } if (mSearchTerm != null) { // If search term is already set here then this fragment is // being restored from a saved state and the search menu item // needs to be expanded and populated again. // Stores the search term (as it will be wiped out by // onQueryTextChange() when the menu item is expanded). final String savedSearchTerm = mSearchTerm; // Expands the search menu item if (Utils.hasICS()) { searchItem.expandActionView(); } // Sets the SearchView to the previous search string searchView.setQuery(savedSearchTerm, false); } } }
From source file:com.chris.ni.omw.ContactsListFragment.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override//from w w w . jav a 2s . c o m public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); // Inflate the menu items inflater.inflate(R.menu.contact_list_menu, menu); // Locate the search item MenuItem searchItem = menu.findItem(R.id.menu_search); // In versions prior to Android 3.0, hides the search item to prevent additional // searches. In Android 3.0 and later, searching is done via a SearchView in the ActionBar. // Since the search doesn't create a new Activity to do the searching, the menu item // doesn't need to be turned off. if (mIsSearchResultView) { searchItem.setVisible(false); } // In version 3.0 and later, sets up and configures the ActionBar SearchView if (Utils.hasHoneycomb()) { // Retrieves the system search manager service final SearchManager searchManager = (SearchManager) getActivity() .getSystemService(Context.SEARCH_SERVICE); // Retrieves the SearchView from the search menu item final SearchView searchView = (SearchView) searchItem.getActionView(); // Assign searchable info to SearchView searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName())); // Set listeners for SearchView searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String queryText) { // Nothing needs to happen when the user submits the search string return true; } @Override public boolean onQueryTextChange(String newText) { // Called when the action bar search text has changed. Updates // the search filter, and restarts the loader to do a new query // using the new search string. String newFilter = !TextUtils.isEmpty(newText) ? newText : null; // Don't do anything if the filter is empty if (mSearchTerm == null && newFilter == null) { return true; } // Don't do anything if the new filter is the same as the current filter if (mSearchTerm != null && mSearchTerm.equals(newFilter)) { return true; } // Updates current filter to new filter mSearchTerm = newFilter; // Restarts the loader. This triggers onCreateLoader(), which builds the // necessary content Uri from mSearchTerm. mSearchQueryChanged = true; getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this); return true; } }); if (Utils.hasICS()) { // This listener added in ICS MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem menuItem) { // Nothing to do when the action item is expanded return true; } @Override public boolean onMenuItemActionCollapse(MenuItem menuItem) { // When the user collapses the SearchView the current search string is // cleared and the loader restarted. if (!TextUtils.isEmpty(mSearchTerm)) { onSelectionCleared(); } mSearchTerm = null; getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this); return true; } }); } if (mSearchTerm != null) { // If search term is already set here then this fragment is // being restored from a saved state and the search menu item // needs to be expanded and populated again. // Stores the search term (as it will be wiped out by // onQueryTextChange() when the menu item is expanded). final String savedSearchTerm = mSearchTerm; // Expands the search menu item if (Utils.hasICS()) { searchItem.expandActionView(); } // Sets the SearchView to the previous search string searchView.setQuery(savedSearchTerm, false); } } }
From source file:android.com.example.contactslist.ui.ContactsListFragment.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override// w w w.j a v a2s . c om public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { // Inflate the menu items inflater.inflate(R.menu.contact_list_menu, menu); // Locate the search item MenuItem searchItem = menu.findItem(R.id.menu_search); // In versions prior to Android 3.0, hides the search item to prevent additional // searches. In Android 3.0 and later, searching is done via a SearchView in the ActionBar. // Since the search doesn't create a new Activity to do the searching, the menu item // doesn't need to be turned off. if (mIsSearchResultView) { searchItem.setVisible(false); } // In version 3.0 and later, sets up and configures the ActionBar SearchView if (Utils.hasHoneycomb()) { // Retrieves the system search manager service final SearchManager searchManager = (SearchManager) getActivity() .getSystemService(Context.SEARCH_SERVICE); // Retrieves the SearchView from the search menu item final SearchView searchView = (SearchView) searchItem.getActionView(); // Assign searchable info to SearchView searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName())); // Set listeners for SearchView searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String queryText) { // Nothing needs to happen when the user submits the search string return true; } @Override public boolean onQueryTextChange(String newText) { // Called when the action bar search text has changed. Updates // the search filter, and restarts the loader to do a new query // using the new search string. String newFilter = !TextUtils.isEmpty(newText) ? newText : null; // Don't do anything if the filter is empty if (mSearchTerm == null && newFilter == null) { return true; } // Don't do anything if the new filter is the same as the current filter if (mSearchTerm != null && mSearchTerm.equals(newFilter)) { return true; } // Updates current filter to new filter mSearchTerm = newFilter; // Restarts the loader. This triggers onCreateLoader(), which builds the // necessary content Uri from mSearchTerm. mSearchQueryChanged = true; getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this); return true; } }); if (Utils.hasICS()) { // This listener added in ICS searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem menuItem) { // Nothing to do when the action item is expanded return true; } @Override public boolean onMenuItemActionCollapse(MenuItem menuItem) { // When the user collapses the SearchView the current search string is // cleared and the loader restarted. if (!TextUtils.isEmpty(mSearchTerm)) { onSelectionCleared(); } mSearchTerm = null; getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this); return true; } }); } if (mSearchTerm != null) { // If search term is already set here then this fragment is // being restored from a saved state and the search menu item // needs to be expanded and populated again. // Stores the search term (as it will be wiped out by // onQueryTextChange() when the menu item is expanded). final String savedSearchTerm = mSearchTerm; // Expands the search menu item if (Utils.hasICS()) { searchItem.expandActionView(); } // Sets the SearchView to the previous search string searchView.setQuery(savedSearchTerm, false); } } }
From source file:com.cypress.cysmart.CommonFragments.ProfileScanningFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.clear();/*from w ww . j ava 2 s .co m*/ inflater.inflate(R.menu.global, menu); MenuItem item = menu.findItem(R.id.graph); MenuItem log = menu.findItem(R.id.log); final MenuItem searchMenuItem = menu.findItem(R.id.search); item.setVisible(false); log.setVisible(true); SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); final SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName())); searchView.setIconifiedByDefault(false); SearchView.OnQueryTextListener textChangeListener = new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextChange(String newText) { // this is your adapter that will be filtered return true; } @Override public boolean onQueryTextSubmit(String query) { if (searchMenuItem != null) { searchMenuItem.collapseActionView(); // this is your adapter that will be filtered if (mLeDeviceListAdapter != null) { searchEnabled = true; searchDeviceList(query); } } return false; } }; searchView.setOnQueryTextListener(textChangeListener); searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean queryTextFocused) { if (!queryTextFocused) { searchMenuItem.collapseActionView(); searchView.setQuery("", false); } } }); super.onCreateOptionsMenu(menu, inflater); }
From source file:br.com.mybaby.contatos.ContactsListFragment.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override//from ww w. j av a 2 s . c o m public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { // Inflate the menu items inflater.inflate(R.menu.contatos_list_menu, menu); // Locate the search item MenuItem searchItem = menu.findItem(R.id.menu_search); // In versions prior to Android 3.0, hides the search item to prevent additional // searches. In Android 3.0 and later, searching is done via a SearchView in the ActionBar. // Since the search doesn't create a new Activity to do the searching, the menu item // doesn't need to be turned off. if (mIsSearchResultView) { searchItem.setVisible(false); } // In version 3.0 and later, sets up and configures the ActionBar SearchView if (Util.hasHoneycomb()) { // Retrieves the system search manager service final SearchManager searchManager = (SearchManager) getActivity() .getSystemService(Context.SEARCH_SERVICE); // Retrieves the SearchView from the search menu item final SearchView searchView = (SearchView) searchItem.getActionView(); // Assign searchable info to SearchView searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName())); // Set listeners for SearchView searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String queryText) { // Nothing needs to happen when the user submits the search string return true; } @Override public boolean onQueryTextChange(String newText) { // Called when the action bar search text has changed. Updates // the search filter, and restarts the loader to do a new query // using the new search string. String newFilter = !TextUtils.isEmpty(newText) ? newText : null; // Don't do anything if the filter is empty if (mSearchTerm == null && newFilter == null) { return true; } // Don't do anything if the new filter is the same as the current filter if (mSearchTerm != null && mSearchTerm.equals(newFilter)) { return true; } // Updates current filter to new filter mSearchTerm = newFilter; // Restarts the loader. This triggers onCreateLoader(), which builds the // necessary content Uri from mSearchTerm. mSearchQueryChanged = true; getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this); return true; } }); if (Util.hasICS()) { // This listener added in ICS searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem menuItem) { // Nothing to do when the action item is expanded return true; } @Override public boolean onMenuItemActionCollapse(MenuItem menuItem) { // When the user collapses the SearchView the current search string is // cleared and the loader restarted. if (!TextUtils.isEmpty(mSearchTerm)) { onSelectionCleared(); } mSearchTerm = null; getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this); return true; } }); } if (mSearchTerm != null) { // If search term is already set here then this fragment is // being restored from a saved state and the search menu item // needs to be expanded and populated again. // Stores the search term (as it will be wiped out by // onQueryTextChange() when the menu item is expanded). final String savedSearchTerm = mSearchTerm; // Expands the search menu item if (Util.hasICS()) { searchItem.expandActionView(); } // Sets the SearchView to the previous search string searchView.setQuery(savedSearchTerm, false); } } }