List of usage examples for android.widget SearchView setOnQueryTextListener
public void setOnQueryTextListener(OnQueryTextListener listener)
From source file:edu.umbc.cs.ebiquity.mithril.parserapp.contentparsers.contacts.ContactsListFragment.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override/*from w w w . ja v a 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 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; if (ParserApplication.getQueryOrLoader() == ParserApplication.getContactButtonLoader()) { /** * If the query text changes for the contact search then the loader is restarted */ getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this); // Toast.makeText(getActivity(), ParserApplication.getQueryOrLoader() // +"and"+ParserApplication.getButtonLoader(), Toast.LENGTH_LONG).show(); } else if (ParserApplication.getQueryOrLoader() .equals(ParserApplication.getContactButtonQuery())) { // Toast.makeText(getActivity(), ParserApplication.getQueryOrLoader(), Toast.LENGTH_LONG).show(); getData(); } 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; if (ParserApplication.getQueryOrLoader() == ParserApplication.getContactButtonLoader()) { /** * If the query text changes for the contact search then the loader is restarted */ getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this); // Toast.makeText(getActivity(), ParserApplication.getQueryOrLoader() // +"and"+ParserApplication.getButtonLoader(), Toast.LENGTH_LONG).show(); } else if (ParserApplication.getQueryOrLoader() .equals(ParserApplication.getContactButtonQuery())) { // Toast.makeText(getActivity(), ParserApplication.getQueryOrLoader(), Toast.LENGTH_LONG).show(); getData(); } 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.example.contactslist.ui.ContactsListFragment.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override//from w w w . ja v a2s . 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 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; /*Uri uri; Cursor[] atomic = new Cursor[phoneNumbers.length]; for(int i=0; i<phoneNumbers.length; i++){ uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumbers[i])); atomic[i] = getActivity().getContentResolver().query(uri, ContactsQuery.PROJECTION, null, null, ContactsQuery.SORT_ORDER); } Cursor extendedCursor = new MergeCursor(atomic);*/ /* Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; String[] projection = new String[] {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER}; String SELECTION = ContactsContract.CommonDataKinds.Phone.NUMBER + " LIKE '%9986395899' OR " + ContactsContract.CommonDataKinds.Phone.NUMBER + " LIKE '%997%'"; Cursor people = getActivity().getContentResolver().query(uri, ContactsQuery.PROJECTION, SELECTION, null, null); mAdapter.swapCursor(people);*/ 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.tweetlanes.android.core.view.BaseLaneActivity.java
void configureActionBarSearchView(Menu menu) { MenuItem searchItem = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) searchItem.getActionView(); searchItem.setShowAsActionFlags(/*from w w w . ja v a 2 s .c om*/ MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); searchView.setOnQueryTextListener(this); OnFocusChangeListener onFocusChangeListener = new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { mCurrentComposeFragment.setIgnoreFocusChange(true); if (mComposeTweetView != null) { mComposeTweetView.setVisibility(View.GONE); } if (mComposeDirectMessageView != null) { mComposeDirectMessageView.setVisibility(View.GONE); } if (!hasFocus) { if (mCurrentComposeFragment == mComposeDirectMessageFragment) { if (mComposeDirectMessageView != null) { mComposeDirectMessageView.setVisibility(View.VISIBLE); } } else { if (mComposeTweetView != null) { mComposeTweetView.setVisibility(View.VISIBLE); } } } mCurrentComposeFragment.setIgnoreFocusChange(false); } }; searchView.setOnQueryTextFocusChangeListener(onFocusChangeListener); searchView.setOnFocusChangeListener(onFocusChangeListener); }
From source file:com.dsdar.thosearoundme.util.ContactsListFragment.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override//from w w w.j av a 2 s .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 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); } } }
From source file:de.enlightened.peris.PerisMain.java
@Override public final boolean onCreateOptionsMenu(final Menu menu) { final MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_menu, menu); final MenuItem searchMenuItem = menu.findItem(R.id.search); final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem); if (this.serverUserid == null || !getString(R.string.subforum_id).contentEquals("0")) { searchView.setVisibility(View.GONE); } else {/*from w w w . j a v a 2 s. c o m*/ if (ThemeSetter.getForegroundDark(this.background)) { searchMenuItem.setIcon(R.drawable.ic_action_search_dark); } } searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() { public void onFocusChange(final View view, final boolean queryTextFocused) { if (!queryTextFocused) { searchMenuItem.collapseActionView(); searchView.setQuery("", false); } } }); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { public boolean onQueryTextChange(final String newText) { // TODO Auto-generated method stub return false; } @SuppressWarnings("checkstyle:requirethis") public boolean onQueryTextSubmit(final String query) { if (getActionBar() != null) { getActionBar().setSubtitle(baseSubtitle); } searchMenuItem.collapseActionView(); searchView.setQuery("", false); final Bundle bundle = new Bundle(); bundle.putString("subforum_name", (String) "Search - " + query); bundle.putString("subforum_id", (String) "search"); bundle.putString("query", (String) query); bundle.putString("background", (String) background); bundle.putString("icon", (String) "n/a"); bundle.putString("inTab", (String) "N"); loadCategory(bundle, "SEARCH_QUERY", false); return false; } }); return true; }
From source file:org.fox.ttrss.OnlineActivity.java
protected void initMenu() { if (m_menu != null) { if (getSessionId() != null) { m_menu.setGroupVisible(R.id.menu_group_logged_in, true); m_menu.setGroupVisible(R.id.menu_group_logged_out, false); } else {/*from www .j a v a 2s .co m*/ m_menu.setGroupVisible(R.id.menu_group_logged_in, false); m_menu.setGroupVisible(R.id.menu_group_logged_out, true); } m_menu.setGroupVisible(R.id.menu_group_headlines, false); m_menu.setGroupVisible(R.id.menu_group_article, false); m_menu.setGroupVisible(R.id.menu_group_feeds, false); m_menu.findItem(R.id.set_labels).setEnabled(getApiLevel() >= 1); m_menu.findItem(R.id.article_set_note).setEnabled(getApiLevel() >= 1); m_menu.findItem(R.id.subscribe_to_feed).setEnabled(getApiLevel() >= 5); MenuItem search = m_menu.findItem(R.id.search); search.setEnabled(getApiLevel() >= 2); ArticlePager ap = (ArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE); if (ap != null) { Article article = ap.getSelectedArticle(); if (article != null) { m_menu.findItem(R.id.toggle_marked).setIcon( article.marked ? R.drawable.ic_important_light : R.drawable.ic_unimportant_light); m_menu.findItem(R.id.toggle_published) .setIcon(article.published ? R.drawable.ic_menu_published_light : R.drawable.ic_menu_unpublished_light); m_menu.findItem(R.id.set_unread) .setIcon(article.unread ? R.drawable.ic_unread_light : R.drawable.ic_read_light); } } HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager() .findFragmentByTag(FRAG_HEADLINES); if (hf != null) { if (hf.getSelectedArticles().size() > 0 && m_headlinesActionMode == null) { m_headlinesActionMode = startActionMode(m_headlinesActionModeCallback); } else if (hf.getSelectedArticles().size() == 0 && m_headlinesActionMode != null) { m_headlinesActionMode.finish(); } } if (!isCompatMode()) { SearchView searchView = (SearchView) search.getActionView(); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { private String query = ""; @Override public boolean onQueryTextSubmit(String query) { HeadlinesFragment frag = (HeadlinesFragment) getSupportFragmentManager() .findFragmentByTag(FRAG_HEADLINES); if (frag != null) { frag.setSearchQuery(query); this.query = query; } return false; } @Override public boolean onQueryTextChange(String newText) { if (newText.equals("") && !newText.equals(this.query)) { HeadlinesFragment frag = (HeadlinesFragment) getSupportFragmentManager() .findFragmentByTag(FRAG_HEADLINES); if (frag != null) { frag.setSearchQuery(newText); this.query = newText; } } return false; } }); } } }
From source file:com.dsdar.thosearoundme.util.MemberAddContactsListFragment.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override//from w w w . j ava 2 s.co 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 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, MemberAddContactsListFragment.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, MemberAddContactsListFragment.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); } } }
From source file:nl.mpcjanssen.simpletask.Simpletask.java
@Override public boolean onCreateOptionsMenu(@NotNull final Menu menu) { MenuInflater inflater = getMenuInflater(); if (m_app.isDarkActionbar()) { inflater.inflate(R.menu.main, menu); } else {/*from w w w . j a v a2s . co m*/ inflater.inflate(R.menu.main_light, menu); } if (!m_app.fileStoreCanSync()) { MenuItem mItem = menu.findItem(R.id.sync); mItem.setVisible(false); } 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.setOnQueryTextListener(new SearchView.OnQueryTextListener() { public boolean m_ignoreSearchChangeCallback; @Override public boolean onQueryTextSubmit(String query) { // Stupid searchview code will call onQueryTextChange callback // When the actionView collapse and the textview is reset // ugly global hack around this m_ignoreSearchChangeCallback = true; menu.findItem(R.id.search).collapseActionView(); m_ignoreSearchChangeCallback = false; return true; } @Override public boolean onQueryTextChange(String newText) { if (!m_ignoreSearchChangeCallback) { if (mFilter == null) { mFilter = new ActiveFilter(); } mFilter.setSearch(newText); mFilter.saveInPrefs(TodoApplication.getPrefs()); if (m_adapter != null) { m_adapter.setFilteredTasks(); } } return true; } }); this.options_menu = menu; return super.onCreateOptionsMenu(menu); }
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//w w w .java2 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:itcr.gitsnes.MainActivity.java
/** * Methods inflate menu options panel/*from w w w . ja va2s. co m*/ * Params: * - [menu] * Returns: * - State of building [true] */ @Override public boolean onCreateOptionsMenu(Menu menu) { /* Inflate the menu; this adds items to the action bar if it is present. */ getMenuInflater().inflate(R.menu.main, menu); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); if (null != searchView) { searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(false); } SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() { public boolean onQueryTextChange(String newText) { // this is your adapter that will be filtered // Log.i("log_tag",newText); return true; } public boolean onQueryTextSubmit(String query) { Log.i("log_tag", query); MasterGames new_fragment = new MasterGames(json_arr); new_fragment.setQname(query); RelativeLayout rl = (RelativeLayout) findViewById(R.id.mainback); rl.setBackgroundColor(Color.parseColor("#009f28")); authButton.setVisibility(View.INVISIBLE); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.placeholder, new_fragment); transaction.addToBackStack(null); transaction.commit(); return true; } }; searchView.setOnQueryTextListener(queryTextListener); return super.onCreateOptionsMenu(menu); }