SearchView setOnQueryTextListener - top ranked examples from Open Source projects

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

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
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
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
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
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
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
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
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
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; 
            } 
4
CodeRank
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; 
            } 
4
CodeRank

Related SearchView setOnQueryTextListener Questions & Answers:

setOnQueryTextListener Method Overview
Sets a listener for user actions within the SearchView.
See Code Examples for other Android SearchView Methods: