Android SearchView - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android SearchView class.

This code example shows how to use the following methods:findViewById, getContext
 
    } 
 
    //can't find a public theme attr to modify actionbar searchview text color 
    public static void customActionBarSearchViewTextColor(SearchView searchView) {
        int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
        TextView textView = (TextView) searchView.findViewById(id);
        textView.setTextColor(Color.WHITE);
 
    } 
 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setOnQueryTextListener
        // Place an action bar item for searching. 
        MenuItem item = menu.add("Search");
        item.setIcon(android.R.drawable.ic_menu_search);
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM
                | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
        SearchView sv = new SearchView(getActivity());
        sv.setOnQueryTextListener(this);
        item.setActionView(sv);
    } 
 
    public boolean onQueryTextChange(String newText) {
        // Called when the action bar search text has changed.  Update 
        // the search filter, and restart the loader to do a new query 
        // with this filter. 
        mCurFilter = !TextUtils.isEmpty(newText) ? newText : null;
        getLoaderManager().restartLoader(0, null, this);
        return true; 
    } 
 
    @Override public boolean onQueryTextSubmit(String query) {
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setOnQueryTextListener
            // Place an action bar item for searching. 
            MenuItem item = menu.add("Search");
            item.setIcon(android.R.drawable.ic_menu_search);
            item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM
                    | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
            SearchView sv = new SearchView(getActivity());
            sv.setOnQueryTextListener(this);
            item.setActionView(sv);
        } 
 
        public boolean onQueryTextChange(String newText) {
            // Called when the action bar search text has changed.  Update 
            // the search filter, and restart the loader to do a new query 
            // with this filter. 
            String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
            // Don't do anything if the filter hasn't actually changed. 
            // Prevents restarting the loader when restoring state. 
            if (mCurFilter == null && newFilter == null) {
                return true; 
            } 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setOnQueryTextListener
            // Place an action bar item for searching. 
            MenuItem item = menu.add("Search");
            item.setIcon(android.R.drawable.ic_menu_search);
            item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM
                    | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
            SearchView sv = new SearchView(getActivity());
            sv.setOnQueryTextListener(this);
            item.setActionView(sv);
        } 
 
        public boolean onQueryTextChange(String newText) {
            // Called when the action bar search text has changed.  Update 
            // the search filter, and restart the loader to do a new query 
            // with this filter. 
            String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
            // Don't do anything if the filter hasn't actually changed. 
            // Prevents restarting the loader when restoring state. 
            if (mCurFilter == null && newFilter == null) {
                return true; 
            } 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setActivated, setIconifiedByDefault, setOnQueryTextListener, setQuery, setQueryHint
 
			} 
		}; 
 
		// attach a search bar where the title would normally be. 
		searchView = new SearchView(getContext());
		searchView.setIconifiedByDefault(false);
		searchView.setActivated(true);
		searchView.setQueryHint("Search " + thingSearched);
		searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
			public boolean onQueryTextSubmit(String query) {
				handler.removeCallbacks(autoSearchRunnable);
				Log.i("HELP", "ME");
				submitSearch(query);
				return true; 
			} 
 
			public boolean onQueryTextChange(String newText) {
				handler.removeCallbacks(autoSearchRunnable);
				currentText = newText;

4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setOnQueryTextListener
        @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
            // Place an action bar item for searching. 
            MenuItem item = menu.add("Search");
            item.setIcon(android.R.drawable.ic_menu_search);
            item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            SearchView sv = new SearchView(getActivity());
            sv.setOnQueryTextListener(this);
            item.setActionView(sv);
        } 
 
        @Override public boolean onQueryTextChange(String newText) {
            // Called when the action bar search text has changed.  Since this 
            // is a simple array adapter, we can just have it do the filtering. 
            mCurFilter = !TextUtils.isEmpty(newText) ? newText : null;
            mAdapter.getFilter().filter(mCurFilter);
            return true; 
        } 
 
        @Override public boolean onQueryTextSubmit(String query) {
            // Don't care about this. 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:requestFocus, getQuery, isIconified, onActionViewCollapsed, onActionViewExpanded
            mActionBar.setDisplayOptions(newFlags, MASK);
        } 
    } 
 
    private void update() { 
        boolean isIconifiedChanging = mSearchView.isIconified() == mSearchMode;
        if (mSearchMode) {
            setFocusOnSearchView(); 
            // Since we have the {@link SearchView} in a custom action bar, we must manually handle 
            // expanding the {@link SearchView} when a search is initiated. Note that a side effect 
            // of this method is that the {@link SearchView} query text is set to empty string. 
            if (isIconifiedChanging) {
                final CharSequence queryText = mSearchView.getQuery();
                mSearchView.onActionViewExpanded();
                if (!TextUtils.isEmpty(queryText)) {
                    mSearchView.setQuery(queryText, false);
                } 
            } 
            if (mActionBar.getNavigationMode() != ActionBar.NAVIGATION_MODE_STANDARD) {
                mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setIconifiedByDefault, setOnQueryTextListener, setQueryHint, setSubmitButtonEnabled
		return super.onCreateOptionsMenu(menu);
	} 
 
	private void setupSearchView(SearchView mSearchView)
	{ 
		mSearchView.setIconifiedByDefault(true);
		mSearchView.setSubmitButtonEnabled(false);
		mSearchView.setOnQueryTextListener(this);
		mSearchView.setQueryHint("Search Contacts");
	} 
	 
	@Override 
	public boolean onQueryTextChange(String newText) {
		// TODO Auto-generated method stub 
		 
		//This line is used if you don't want to show the pop up and enable your own filter. 
		filter.filter(newText);
		//This code shows the popup view which blocks other views behind it, plus it is ugly! 
		 
//		if(TextUtils.isEmpty(newText)) 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setOnQueryTextListener
	public void initMenu(Menu menu) {
		itemSearch = menu.add(0, 3, 98,
				"Search"); 
		itemSearch.setIcon(android.R.drawable.ic_menu_search);
		itemSearch.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
		SearchView sv = new SearchView(getActivity());
		sv.setOnQueryTextListener(this);
		itemSearch.setActionView(sv);
	} 
 
	@Override 
	public void onGetNewArguments(Bundle bn) {
 
	} 
 
	@Override 
	public void onLoadComplete(Loader<List<String>> loader, List<String> data) {
		list.clear();
		if (data != null) {
			list.addAll(data);
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setOnQueryTextListener
		// getMenuInflater().inflate(R.menu.activity_main, menu); 
 
		MenuItem item = menu.add("Search");
		item.setIcon(android.R.drawable.ic_menu_search);
		item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
		SearchView searchView = new SearchView(ContactSearchActivity_2.this);
		searchView.setOnQueryTextListener(this);
		// Suchfeld weiss faerben 
		searchView.setBackgroundColor(-1);
		item.setActionView(searchView);
 
		return true; 
	} 
 
	@Override 
	public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
		Uri baseUri;
		if (cursorFilter != null) {
			baseUri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI,
					Uri.encode(cursorFilter));
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android SearchView Questions & Answers:

Other Android SearchView Examples

5:			// Associate searchable configuration with the SearchView
6:			SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
7:			SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
8:					.getActionView();
9:			searchView.setSearchableInfo(searchManager
-
5:			// Associate searchable configuration with the SearchView
6:			SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
7:			SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
8:					.getActionView();
9:			searchView.setSearchableInfo(searchManager

Read More

See Code Examples for Android SearchView Methods: