List of usage examples for android.widget SearchView setOnQueryTextListener
public void setOnQueryTextListener(OnQueryTextListener listener)
From source file:com.jhk.whysoformal.activity.musiclist.fragment.MusicListFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.menu_fragment_list_music, menu); MenuItem searchItem = menu.findItem(R.id.list_music_fragment_menu_item_search); SearchView searchView = (SearchView) searchItem.getActionView(); SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); //SearchableInfo searchInfo = searchManager.getSearchableInfo(getActivity().getComponentName()); //searchView.setSearchableInfo(searchInfo); searchView.setOnQueryTextListener(this); }
From source file:com.peaceworld.wikisms.view.newui.BaseActivity.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void handleSearchForSdkAbove11() { MenuItem menuItem = menu.findItem(R.id.search); menuItem.setVisible(false);//from w w w . j a v a 2s . c o m SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView search = (SearchView) menu.findItem(R.id.menu_search).getActionView(); search.setSearchableInfo(manager.getSearchableInfo(getComponentName())); search.setOnQueryTextListener(new OnQueryTextListener() { @Override public boolean onQueryTextChange(String query) { loadData(query); return true; } @Override public boolean onQueryTextSubmit(String arg0) { return false; } }); }
From source file:edu.ucsb.cs.cs185.inspirante.searchbyranking.SearchByRankingFragment.java
@Override public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_search_by_ranking, container, false); final SearchView searchView = (SearchView) rootView.findViewById(R.id.search_by_ranking_search_view); int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null); EditText searchEditText = (EditText) searchView.findViewById(id); searchEditText.setTextColor(Color.GRAY); searchEditText.setHintTextColor(Color.GRAY); searchView.setOnQueryTextListener(searchViewListener); searchView.setMaxWidth(Integer.MAX_VALUE); searchView.setOnClickListener(new View.OnClickListener() { @Override// www . jav a 2 s . c om public void onClick(View view) { searchView.setFocusable(true); searchView.setIconified(false); searchView.requestFocusFromTouch(); } }); mInspireRecyclerView = (RecyclerView) rootView.findViewById(R.id.search_rv); mInspireRecyclerView.setHasFixedSize(true); mInspireRecyclerView.setNestedScrollingEnabled(false); frequentTags = ItemCards.getInstance(getContext()).getFrequentTags(); mInspireAdapter = new RankByTagAdapter(getContext(), this, frequentTags); mInspireAdapter.setHasStableIds(true); mLayoutManager = new LinearLayoutManager(getContext()); mLayoutManager.setItemPrefetchEnabled(true); mInspireRecyclerView.setLayoutManager(mLayoutManager); mInspireAdapter.setOnItemClickListener(new RankByTagAdapter.OnRecyclerViewItemClickListener() { @Override public void onItemClick(View view, int position) { TextView tv = (TextView) view; Intent intent = new Intent(getActivity(), TagAndImagesActivity.class); intent.putExtra("TAG", tv.getText()); startActivity(intent); } }); ItemCards itemCards = ItemCards.getInstance(getContext()); itemCards.setAdapter(mInspireAdapter); mInspireRecyclerView.setAdapter(mInspireAdapter); mInspireAdapter.notifyDataSetChanged(); // Set Tag recycler view mTagRecyclerView = (RecyclerView) rootView.findViewById(R.id.search_tags_rv); mTagRecyclerView.setHasFixedSize(true); mTagRecyclerView.setNestedScrollingEnabled(false); mTagsAdapter = new TagsAdapter(getContext(), frequentTags); mTagsAdapter.setHasStableIds(true); RecyclerView.LayoutManager tagsLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false); tagsLayoutManager.setItemPrefetchEnabled(true); mTagRecyclerView.setLayoutManager(tagsLayoutManager); mTagsAdapter.setOnItemClickListener(new TagsAdapter.OnRecyclerViewItemClickListener() { @Override public void onItemClick(View view, int position) { String tag = mTagsAdapter.getTag(position); searchViewListener.onQueryTextChange(tag); //searchView.setFocus searchView.setQuery(tag, true); searchView.setIconified(false); searchView.clearFocus(); mLayoutManager.scrollToPosition(0); } }); mTagRecyclerView.setAdapter(mTagsAdapter); mTagsAdapter.notifyDataSetChanged(); return rootView; }
From source file:ch.luklanis.esscan.history.HistoryActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { if (mHistoryManager.hasHistoryItems()) { getMenuInflater().inflate(R.menu.history_menu, menu); SearchView searchView = (SearchView) menu.findItem(R.id.history_menu_search).getActionView(); searchView.setOnQueryTextListener(queryListener); MenuItem copyItem = menu.findItem(R.id.history_menu_copy_code_row); MenuItem sendItem = menu.findItem(R.id.history_menu_send_code_row); if (twoPane && this.historyFragment.getActivatedPosition() != ListView.INVALID_POSITION) { copyItem.setVisible(true);// w ww.j a v a2 s . c o m sendItem.setVisible(true); } else { copyItem.setVisible(false); sendItem.setVisible(false); } MenuItem item = menu.findItem(R.id.history_menu_send_dta); if (dtaFileCreator.getFirstErrorId() != 0) { item.setVisible(false); } return true; } return false; }
From source file:inc.bait.jubilee.ui.fragments.ContactsListFragment.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override/*from w w w . j av a 2 s . c om*/ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.contact_list_menu, menu); MenuItem searchItem = menu.findItem(R.id.menu_search); if (isSearchResultView) { searchItem.setVisible(false); } if (ApiHelper.hasHoneycomb()) { final SearchManager searchManager = (SearchManager) getActivity() .getSystemService(Context.SEARCH_SERVICE); final SearchView searchView = (SearchView) searchItem.getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName())); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String queryText) { return true; } @Override public boolean onQueryTextChange(String newText) { String newFilter = !TextUtils.isEmpty(newText) ? newText : null; if (searchString == null && newFilter == null) { return true; } if (searchString != null && searchString.equals(newFilter)) { return true; } searchString = newFilter; mSearchQueryChanged = true; getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this); return true; } }); if (ApiHelper.hasICS()) { searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem menuItem) { return true; } @Override public boolean onMenuItemActionCollapse(MenuItem menuItem) { if (!TextUtils.isEmpty(searchString)) { onSelectionCleared(); } searchString = null; getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this); return true; } }); } if (searchString != null) { final String savedSearchTerm = searchString; // Expands the search menu item if (ApiHelper.hasICS()) { searchItem.expandActionView(); } searchView.setQuery(savedSearchTerm, false); } } }
From source file:com.hybris.mobile.activity.StoreLocatorActivity.java
/** * Menu methods/* w w w. j a v a 2 s . co m*/ */ @Override public boolean onCreateOptionsMenu(final Menu menu) { MenuInflater inflater = this.getMenuInflater(); inflater.inflate(R.menu.store_finder, menu); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); MenuItem searchViewMenuItem = menu.findItem(R.id.store_search); this.mSearchView = searchViewMenuItem; SearchView searchView = ((SearchView) searchViewMenuItem.getActionView()); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(true); searchView.setQueryHint(getResources().getString(R.string.store_search_hint)); searchView.setOnQueryTextListener(this); return true; }
From source file:org.jitsi.android.gui.contactlist.ContactListFragment.java
/** * {@inheritDoc}/*from w ww .j a va 2 s .c o m*/ */ @Override public void onPause() { super.onPause(); // Unbind search listener if (searchItem != null) { SearchView searchView = (SearchView) searchItem.getActionView(); searchView.setOnQueryTextListener(null); searchView.setOnCloseListener(null); } // Save scroll position scrollPosition = contactListView.getFirstVisiblePosition(); View itemView = contactListView.getChildAt(0); scrollTopPosition = itemView == null ? 0 : itemView.getTop(); // Dispose of group expand memory if (listExpandHandler != null) { listExpandHandler.unbind(); listExpandHandler = null; } contactListView.setAdapter((ExpandableListAdapter) null); if (contactListAdapter != null) { contactListAdapter.dispose(); contactListAdapter = null; } disposeSourcesAdapter(); }
From source file:br.com.GUI.perfil.MeusAlunos.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.adicionar_aluno_actions, menu); final SearchView searchView = new SearchView(getActivity().getActionBar().getThemedContext()); searchView.setQueryHint("Search"); menu.add(Menu.NONE, Menu.NONE, 1, "@string").setIcon(android.R.drawable.ic_menu_search) .setActionView(searchView)//from w ww. j ava2 s . com .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); searchView.setOnQueryTextListener(new OnQueryTextListener() { @Override public boolean onQueryTextChange(String newText) { if (newText.length() > 0) { // Search atualizarMeusAlunos(newText.toString()); } else { // Do something when there's no input atualizarMeusAlunos(newText.toString()); } return false; } @Override public boolean onQueryTextSubmit(String arg0) { // TODO Auto-generated method stub atualizarMeusAlunos(arg0.toString()); return false; } }); }
From source file:br.com.GUI.aulas.Agenda.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.agenda_actions, menu); final SearchView searchView = new SearchView(getActivity().getActionBar().getThemedContext()); searchView.setQueryHint("Search"); menu.add(Menu.NONE, Menu.NONE, 1, "@string").setIcon(android.R.drawable.ic_menu_search) .setActionView(searchView)/*from ww w. j a v a 2 s. c o m*/ .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); searchView.setOnQueryTextListener(new OnQueryTextListener() { @Override public boolean onQueryTextChange(String newText) { if (newText.length() > 0) { // Search atualizarAgenda(newText.toString()); } else { // Do something when there's no input atualizarAgenda(newText.toString()); } return false; } @Override public boolean onQueryTextSubmit(String arg0) { // TODO Auto-generated method stub atualizarAgenda(arg0.toString()); return false; } }); }
From source file:dev.vision.shopping.center.Fragments.GourmetFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { //inflater.inflate(R.menu.main, menu); inflater.inflate(R.menu.offers, menu); MenuItem searchItem = menu.findItem(R.id.action_search); MenuItem expand = menu.findItem(R.id.expand); expand.setVisible(false);/* w ww . j a va2 s . c o m*/ SearchView searchView = null; searchView = (SearchView) MenuItemCompat.getActionView(searchItem); if (searchView == null) searchView = (SearchView) searchItem.getActionView(); SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName())); searchView.setOnQueryTextListener(this); }