SearchView setQuery - 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 setQuery method.

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: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
This code example shows how to use the following methods:clearFocus, setQuery
            Log.e(Debug.TAG, "Array of suggestions isn't valid JSON");
        } 
    } 
 
    private void resetSearch () { 
        mSearchView.setQuery("", false);
        mSearchView.clearFocus();
    } 
 
    private void submitQuery (String query, int cursorPosition) {
        if (mSuggestAdapter.getCount() > 0) {
            if (cursorPosition == -1) { // didn't click suggestion
                mSuggestCursor.moveToFirst();
            } 
            String topHitTitle =
                    mSuggestCursor.getString(mSuggestCursor.getColumnIndex(SUGGEST_TITLE_LABEL));
            String topHitUrl =
                    mSuggestCursor.getString(mSuggestCursor.getColumnIndex(SUGGEST_URL_LABEL));
            resetSearch(); 
            mParent.showText("Loading: " + topHitTitle);
4
CodeRank
This code example shows how to use the following methods:getQuery, setQuery
        return true; 
    } 
 
    @Override 
    public boolean onClose() { 
        if (!TextUtils.isEmpty(mSearchView.getQuery())) {
            mSearchView.setQuery(null, true);
        } 
        return true; 
    } 
 
    @Override  
    public void onListItemClick(ListView l, View v, int position, long id) {
        // Insert desired behavior here. 
        Log.i("FragmentComplexList", "Item clicked: " + id);
    } 
 
    // These are the Contacts rows that we will retrieve. 
    static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] {
        Contacts._ID,
4
CodeRank
This code example shows how to use the following methods:getQuery, setQuery
        return true; 
    } 
 
    @Override 
    public boolean onClose() { 
        if (!TextUtils.isEmpty(mSearchView.getQuery())) {
            mSearchView.setQuery(null, true);
        } 
 
        return true; 
    } 
} 
4
CodeRank
This code example shows how to use the following methods:setIconified, setQuery
	@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
	public static void collapseSearchView(SearchView sv, Menu menu, int menuItemId) {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
			menu.findItem(menuItemId).collapseActionView();
		} else { 
			sv.setQuery(null, false);
			sv.setIconified(true);
		} 
	} 
 
	public static ProgressDialog createProgressDialog(Context context, int messageStringId) {
		ProgressDialog d = new ProgressDialog(context);
		d.setMessage(context.getString(messageStringId));
		return d;
	} 
 
	public static TextView createTextView(Context context, int layoutId, int stringId) {
		TextView t = (TextView) View.inflate(context, layoutId, null);
		t.setText(stringId);
		return t;
4
CodeRank
This code example shows how to use the following methods:getQuery, setQuery
            return true; 
        } 
 
        @Override 
        public boolean onClose() { 
            if (!TextUtils.isEmpty(mSearchView.getQuery())) {
                mSearchView.setQuery(null, true);
            } 
            return true; 
        } 
 
        @Override public void onListItemClick(ListView l, View v, int position, long id) {
            // Insert desired behavior here. 
            Log.i("CustomLoader", "Item clicked: " + id);
        } 
 
        @Override public Loader<List<AppEntry>> onCreateLoader(int id, Bundle args) {
            // This is called when a new Loader needs to be created.  This 
            // sample only has one Loader with no arguments, so it is simple. 
            return new AppListLoader(getActivity());
4
CodeRank
This code example shows how to use the following methods:setQuery
 
                MenuItem.OnActionExpandListener onActionExpandListener = new MenuItem.OnActionExpandListener() {
                    @Override 
                    public boolean onMenuItemActionCollapse(MenuItem item) {
                        Log.d("ppgllrd", "onMenuItemActionCollapse");
                        searchView.setQuery(null, true);
                        setFilter(""); 
                        // Return true to collapse action view 
                        return true; 
                    } 
 
                    @Override 
                    public boolean onMenuItemActionExpand(MenuItem item) {
                        Log.d("ppgllrd", "onMenuItemActionExpand "+query);
                        //searchView.setQuery(query, false); 
                        searchView.setQueryHint("type to search");
                        return true; 
                    } 
                }; 
                if (onActionExpandListener != null)
3
CodeRank
This code example shows how to use the following methods:setQuery
	@SuppressWarnings("unused") 
	private void initQuerySearchView(CharSequence s) {
		final int SEARCHVIEW_FIELD_ID = 0;
		SearchView searchView = (SearchView) this
				.findViewById(SEARCHVIEW_FIELD_ID);
		searchView.setQuery(s, false);
	} 
 
	/** 
	 * Exported, because unused. 
	 */ 
	@SuppressWarnings("unused") 
	private void initSearchView() { 
		final int SEARCHVIEW_FIELD_ID = 0;
		// Get the SearchView and set the searchable configuration 
		SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
		searchField.addTextChangedListener(this);
 
		SearchView searchView = (SearchView) this
				.findViewById(SEARCHVIEW_FIELD_ID);
4
CodeRank

Related SearchView setQuery Questions & Answers:

setQuery Method Overview
Sets a query string in the text field and optionally submits the query as well.
See Code Examples for other Android SearchView Methods: