List of usage examples for android.widget SearchView setSubmitButtonEnabled
public void setSubmitButtonEnabled(boolean enabled)
From source file:net.ustyugov.jtalk.activity.XMLConsole.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.xml, menu);/*from w ww .j a v a2s.c om*/ MenuItem.OnActionExpandListener listener = new MenuItem.OnActionExpandListener() { @Override public boolean onMenuItemActionCollapse(MenuItem item) { searchString = ""; updateList(); return true; } @Override public boolean onMenuItemActionExpand(MenuItem item) { return true; } }; SearchView searchView = new SearchView(this); searchView.setQueryHint(getString(android.R.string.search_go)); searchView.setSubmitButtonEnabled(true); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextChange(String newText) { return false; } @Override public boolean onQueryTextSubmit(String query) { searchString = query; updateList(); return true; } }); MenuItem item = menu.findItem(R.id.search); item.setActionView(searchView); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); item.setOnActionExpandListener(listener); return super.onCreateOptionsMenu(menu); }
From source file:no.group09.ucsoftwarestore.MainFragmentActivity.java
/** * Creates options menu// www .j a va 2 s.co m */ @SuppressLint("NewApi") @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main_menu, menu); //When the menu is created, check the preferences and set the correct text if (sharedPref.getBoolean("hide_incompatible", false)) { menu.getItem(1).setTitle("Hide incompatible"); menu.getItem(1).setChecked(true); } else { menu.getItem(1).setTitle("Hide incompatible"); menu.getItem(1).setChecked(false); } //Search bar for versions over API level 11 int SDK_INT = android.os.Build.VERSION.SDK_INT; if (SDK_INT >= 11) { SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setSubmitButtonEnabled(true); } return true; }
From source file:com.deliciousdroid.activity.FragmentBaseActivity.java
@TargetApi(11) public void setupSearch(Menu menu) { if (android.os.Build.VERSION.SDK_INT >= 11) { SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setSubmitButtonEnabled(false); }//w w w . ja va 2 s .c o m }
From source file:no.group09.ucsoftwarestore.MainActivity.java
/** * Creates options menu//from w w w. j a va 2 s .c o m */ @SuppressLint("NewApi") @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main_menu, menu); //When the menu is created, check the preferences and set the correct text if (sharedPref.getBoolean("hide_incompatible", false)) { menu.getItem(1).setTitle("Hide incompatible"); menu.getItem(1).setChecked(true); } else { menu.getItem(1).setTitle("Hide incompatible"); menu.getItem(1).setChecked(false); } //Search bar for versions over API level 11 int SDK_INT = android.os.Build.VERSION.SDK_INT; if (SDK_INT >= 11) { SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setSubmitButtonEnabled(true); } return true; }
From source file:com.einzig.ipst2.activities.PSListActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu_pslistactivity, menu); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.search_pslistactivity).getActionView(); if (searchView != null) { searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setSubmitButtonEnabled(true); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override/*from ww w. j a v a 2 s .c o m*/ public boolean onQueryTextChange(String newText) { if (TextUtils.isEmpty(newText)) { ((ListItemAdapter_PS) listView.getAdapter()).resetData(); } else { ((ListItemAdapter_PS) listView.getAdapter()).getFilter().filter(newText); } return false; } @Override public boolean onQueryTextSubmit(String query) { return false; } }); } else Logger.d("MENU ITEM ACTION VIEW FOR SEARCH IS NULL"); return true; }
From source file:com.aboveware.actionbar.honeycomb.ActionBarHelperHoneycomb.java
@Override public boolean onCreateOptionsMenu(Menu menu) { mOptionsMenu = menu;//from ww w .j a v a2 s .c o m MenuItem searchItem = menu.findItem(R.id.menu_search); if (searchItem != null) { final SearchView searchView = (SearchView) searchItem.getActionView(); searchView.setIconifiedByDefault(false); searchView.setSubmitButtonEnabled(true); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return iDocument.searchSubmit(query); } @Override public boolean onQueryTextChange(String newText) { return iDocument.search(newText); } }); } boolean returnValue = super.onCreateOptionsMenu(menu); if (shouldBeRefreshing) { setRefreshActionItemState(true); } shouldBeRefreshing = false; return returnValue; }
From source file:com.example.lowviscam.GalleryActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu items for use in the action bar MenuInflater inflater = getMenuInflater(); if (isLight == true) { inflater.inflate(R.menu.gallery, menu); } else {//www. j a v a 2 s. c om inflater.inflate(R.menu.gallery_dark, menu); } // Get the SearchView and set the searchable configuration SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); // Assumes current activity is the searchable activity searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default searchView.setSubmitButtonEnabled(true); searchView.setOnQueryTextListener(new OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { search(query); // First image toast String firstResult; if (numSearchResults == 0) { firstResult = "No results found for " + query + "."; } else { firstResult = "The first image result is titled " + tagList[0]; } SpannableString s = new SpannableString(firstResult); s.setSpan(new TypefaceSpan(GalleryActivity.this, "APHont-Regular_q15c.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); Toast.makeText(GalleryActivity.this, s, Toast.LENGTH_LONG).show(); return true; } @Override public boolean onQueryTextChange(String newText) { if (TextUtils.isEmpty(newText)) { search(""); } return true; } public void search(String query) { // hide keyboard InputMethodManager inputManager = (InputMethodManager) GalleryActivity.this .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(GalleryActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); // Fetch the {@link LayoutInflater} service so that new views can be created LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); // Find the {@link GridView} that was already defined in the XML layout GridView gridView = (GridView) findViewById(R.id.grid); try { gridView.setAdapter(new CouponAdapter(inflater, createSearchedCoupons(query))); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); return true; //return super.onCreateOptionsMenu(menu); }
From source file:net.nightwhistler.pageturner.activity.ReadingFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.reading_menu, menu); this.searchMenuItem = menu.findItem(R.id.search_text); if (this.searchMenuItem != null) { final com.actionbarsherlock.widget.SearchView searchView = (com.actionbarsherlock.widget.SearchView) searchMenuItem .getActionView();//from w ww . j a v a 2s . c o m if (searchView != null) { searchView.setSubmitButtonEnabled(true); searchView .setOnQueryTextListener(new com.actionbarsherlock.widget.SearchView.OnQueryTextListener() { //This is a work-around, since we get the onQuerySubmit() event twice //when the user hits enter private String lastQuery = ""; @Override public boolean onQueryTextSubmit(String query) { if (query.equals(lastQuery) && searchResults != null) { showSearchResultDialog(searchResults); } else if (!query.equals(lastQuery)) { searchResults = null; lastQuery = query; performSearch(query); } return true; } @Override public boolean onQueryTextChange(String newText) { return false; } }); } } }