List of usage examples for android.widget SearchView setOnQueryTextListener
public void setOnQueryTextListener(OnQueryTextListener listener)
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/* ww w.j a v a2s. co 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:net.abcdroid.devfest12.ui.SearchActivity.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void setupSearchMenuItem(Menu menu) { final MenuItem searchItem = menu.findItem(R.id.menu_search); if (searchItem != null && UIUtils.hasHoneycomb()) { SearchView searchView = (SearchView) searchItem.getActionView(); if (searchView != null) { SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override//from ww w. j av a 2 s.com public boolean onQueryTextSubmit(String s) { ReflectionUtils.tryInvoke(searchItem, "collapseActionView"); return false; } @Override public boolean onQueryTextChange(String s) { return false; } }); searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionSelect(int i) { return false; } @Override public boolean onSuggestionClick(int i) { ReflectionUtils.tryInvoke(searchItem, "collapseActionView"); return false; } }); } } }
From source file:com.securecomcode.voice.ui.ContactsListActivity.java
@SuppressLint({ "NewApi", "NewApi" }) private void initializeSearch(android.widget.SearchView searchView) { searchView.setOnQueryTextListener(new android.widget.SearchView.OnQueryTextListener() { @Override// www. j a v a 2s . c o m public boolean onQueryTextSubmit(String query) { ArrayList<Contact> searchList = new ArrayList<Contact>(); for (Contact c : contactList) { if (query.length() <= c.getContactName().length()) { if (c.getContactName().toLowerCase().contains(query.toLowerCase())) { searchList.add(c); } } for (String number : c.getPhoneNumber()) { if (query.length() <= number.length()) { String s = number; if (!Util.isValidEmail(s) && !s.contains("@")) { s = s.replace("(", ""); s = s.replace(")", ""); s = s.replace("-", ""); s = s.replace(" ", ""); s = s.length() > 10 ? s.substring(s.length() - 10) : s; } if (s.toLowerCase().contains(query.toLowerCase())) { if (!searchList.contains(c)) { searchList.add(c); } } } } } if (searchList.size() == 0) { ((TextView) getListView().getEmptyView()) .setText(R.string.ContactsListActivity_no_contacts_found); } setAdapter(searchList); return true; } @Override public boolean onQueryTextChange(String newText) { return onQueryTextSubmit(newText); } }); }
From source file:net.seedboxer.seedroid.activities.fragments.DownloadsFragment.java
/** * Get the SearchView and set the searchable configuration * @param menu/* w w w.j av a2 s . c o m*/ */ private void createFilteredMenu(Menu menu) { SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName())); searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default searchView.setOnQueryTextListener(new OnQueryTextListener() { public boolean onQueryTextSubmit(String query) { adapter.getFilter().filter(query); return true; } public boolean onQueryTextChange(String newText) { adapter.getFilter().filter(newText); return true; } }); }
From source file:com.aboveware.actionbar.honeycomb.ActionBarHelperHoneycomb.java
@Override public boolean onCreateOptionsMenu(Menu menu) { mOptionsMenu = menu;// ww w.j a v a 2s .com 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.melchor629.musicote.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { //Create the search view SearchView searchView = new SearchView(getActionBar().getThemedContext()); searchView.setQueryHint(getResources().getString(R.string.menu_search)); searchView.setOnQueryTextListener(this); menu.add("Search") .setIcon(new IconDrawable(this, Iconify.IconValue.fa_search).color(Color.WHITE).actionBarSize())//android.R.drawable.ic_menu_search) .setActionView(searchView)//www .j a va 2s. c o m .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); getMenuInflater().inflate(R.menu.main, menu); menu.findItem(R.id.ajustesm) .setIcon(new IconDrawable(this, Iconify.IconValue.fa_cogs).color(Color.WHITE).actionBarSize()); menu.findItem(R.id.parar) .setIcon(new IconDrawable(this, Iconify.IconValue.fa_music).color(Color.WHITE).actionBarSize()); return true; }
From source file:com.jbirdvegas.mgerrit.ProjectsList.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the options menu from XML MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.projects_menu, menu); // Get the SearchView and set the searchable configuration SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); // Assumes current activity is the searchable activity searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(true); searchView.setOnQueryTextListener(this); return true;/* w w w. java2 s . c o m*/ }
From source file:com.conferenceengineer.android.iosched.ui.SearchActivity.java
@Override @TargetApi(Build.VERSION_CODES.HONEYCOMB) public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.search, menu); final MenuItem searchItem = menu.findItem(R.id.menu_search); if (searchItem != null && UIUtils.hasHoneycomb()) { SearchView searchView = (SearchView) searchItem.getActionView(); if (searchView != null) { SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setQueryRefinementEnabled(true); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override/*from w w w .jav a2 s.c o m*/ public boolean onQueryTextSubmit(String s) { ReflectionUtils.tryInvoke(searchItem, "collapseActionView"); return false; } @Override public boolean onQueryTextChange(String s) { return false; } }); searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionSelect(int i) { return false; } @Override public boolean onSuggestionClick(int i) { ReflectionUtils.tryInvoke(searchItem, "collapseActionView"); return false; } }); } } return true; }
From source file:org.namelessrom.devicecontrol.modules.appmanager.BaseAppListFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_app_list, menu); // setup search final MenuItem searchItem = menu.findItem(R.id.action_search); final SearchView searchView = (searchItem != null ? (SearchView) searchItem.getActionView() : null); if (searchView != null) { searchView.setOnQueryTextListener(this); searchView.setOnCloseListener(this); }/*from w ww . j a va 2 s . c o m*/ super.onCreateOptionsMenu(menu, inflater); }
From source file:com.numenta.taurus.instance.InstanceListActivity.java
private void configureSearchView(@NonNull final SearchView searchView) { SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); // Assumes current activity is the searchable activity searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); // Handle query events searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override//from w w w .j a v a 2s .c o m public boolean onQueryTextSubmit(String query) { // Hide Keyboard on submit InputMethodManager imm = (InputMethodManager) searchView.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { imm.hideSoftInputFromWindow(searchView.getWindowToken(), 0); } return true; } @Override public boolean onQueryTextChange(String newText) { // Filter list as the user types _listFragment.applyFilter(newText); return true; } }); // FIXME: Android does not support styling the search view across all versions. // For now, "peek" into internal API to make the appropriate changes to the SearchView. // In the future we should use the official android API to customize the SearchView widget. // See android.R.layout.search_view for the layout we are "peeking". It is no guarantee it // will work on all public android versions and/or OEM customizations. // This HACK is only valid for the POC phase. We should find a better solution before releasing Resources resources = searchView.getResources(); // Style search box and text int searchPlateId = resources.getIdentifier("android:id/search_plate", null, null); View searchPlate = searchView.findViewById(searchPlateId); if (searchPlate != null) { int searchTextId = resources.getIdentifier("android:id/search_src_text", null, null); TextView searchText = (TextView) searchPlate.findViewById(searchTextId); if (searchText != null) { searchPlate.setBackgroundResource(android.R.drawable.editbox_background); searchText.setPadding(5, 0, 0, 0); searchText.setTextColor(Color.BLACK); searchText.setHintTextColor(Color.LTGRAY); } } }