Java Code Examples for android.widget.SearchView#setQueryHint()

The following examples show how to use android.widget.SearchView#setQueryHint() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From ActivityLauncher with ISC License 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);

    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setQueryHint(this.getText(R.string.filter_hint));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            onFilter(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            onFilter(newText);
            return true;
        }
    });

    return true;
}
 
Example 2
Source File: FollowedPeople.java    From Klyph with MIT License 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{
	if (getAdapter() != null && getAdapter().getCount() > 0)
	{
		// Create the search view
		SearchView searchView = new SearchView(((FragmentActivity) getActivity()).getActionBar()
				.getThemedContext());
		searchView.setQueryHint("Search for people");
		searchView.setOnQueryTextListener(this);

		menu.add("Search").setIcon(AttrUtil.getResourceId(getActivity(), R.attr.searchIcon))
				.setActionView(searchView)
				.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
	}

	super.onCreateOptionsMenu(menu, inflater);
}
 
Example 3
Source File: Groups.java    From Klyph with MIT License 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{
	if (getAdapter() != null && getAdapter().getCount() > 0)
	{
		// Create the search view
		SearchView searchView = new SearchView(((FragmentActivity) getActivity()).getActionBar()
				.getThemedContext());
		searchView.setQueryHint("Search for groups");
		searchView.setOnQueryTextListener(this);

		menu.add("Search").setIcon(AttrUtil.getResourceId(getActivity(), R.attr.searchIcon))
				.setActionView(searchView)
				.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
	}

	super.onCreateOptionsMenu(menu, inflater);
}
 
Example 4
Source File: Friends.java    From Klyph with MIT License 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{
	if (getAdapter() != null && getAdapter().getCount() > 0)
	{
		// Create the search view
		SearchView searchView = new SearchView(((FragmentActivity) getActivity()).getActionBar()
				.getThemedContext());
		searchView.setQueryHint("Search for friends");
		searchView.setOnQueryTextListener(this);

		menu.add("Search").setIcon(AttrUtil.getResourceId(getActivity(), R.attr.searchIcon))
				.setActionView(searchView)
				.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
	}

	super.onCreateOptionsMenu(menu, inflater);
}
 
Example 5
Source File: ProgrammaticAutocompleteToolbarActivity.java    From android-places-demos with Apache License 2.0 5 votes vote down vote up
private void initSearchView(SearchView searchView) {
    searchView.setQueryHint(getString(R.string.search_a_place));
    searchView.setIconifiedByDefault(false);
    searchView.setFocusable(true);
    searchView.setIconified(false);
    searchView.requestFocusFromTouch();
    searchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            progressBar.setIndeterminate(true);

            // Cancel any previous place prediction requests
            handler.removeCallbacksAndMessages(null);

            // Start a new place prediction request in 300 ms
            handler.postDelayed(() -> {
                getPlacePredictions(newText);
            }, 300);
            return true;
        }
    });
}
 
Example 6
Source File: ProgrammaticAutocompleteToolbarActivity.java    From android-places-demos with Apache License 2.0 5 votes vote down vote up
private void initSearchView(SearchView searchView) {
    searchView.setQueryHint(getString(R.string.search_a_place));
    searchView.setIconifiedByDefault(false);
    searchView.setFocusable(true);
    searchView.setIconified(false);
    searchView.requestFocusFromTouch();
    searchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            progressBar.setIndeterminate(true);

            // Cancel any previous place prediction requests
            handler.removeCallbacksAndMessages(null);

            // Start a new place prediction request in 300 ms
            handler.postDelayed(() -> {
                getPlacePredictions(newText);
            }, 300);
            return true;
        }
    });
}
 
Example 7
Source File: AddItemShoppingList.java    From ShoppingList with MIT License 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
	getMenuInflater().inflate(R.menu.add_item_shopping_list_menu, menu);

	MenuItem searchItem = menu.findItem(R.id.search);
	mSearchView = (SearchView) searchItem.getActionView();
	mSearchView.setOnQueryTextListener(this);
	mSearchView.setQueryHint("Pesquisar");

	return true;
}
 
Example 8
Source File: MainActivity.java    From dttv-android with GNU General Public License v3.0 5 votes vote down vote up
protected void createActionMode(int mode, Menu menu) {
     menu.clear();
     switch (mode) {
         case Constant.LOCAL_VIDEO:
             SearchView searchView = new SearchView(this);
             searchView.setMaxWidth(600);
             searchView.setQueryHint("input words");
             searchView.setOnQueryTextListener(this);
             searchView.setOnSuggestionListener(this);

/*menu.add("Search").setIcon(R.drawable.dt_action_search_icon)
.setActionView(searchView)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);*/
             menu.add("Refresh").setIcon(R.drawable.dt_action_refresh_icon)
                     .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

             menu.add("Setting").setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
             break;
         case Constant.LOCAL_AUDIO:
             menu.add("Plus").setIcon(R.drawable.dt_action_plus_icon)
                     .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
             menu.add("Setting").setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
             break;
         case Constant.LOCAL_FILE:
             menu.add("Refresh").setIcon(R.drawable.dt_action_refresh_icon)
                     .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
             menu.add("Setting").setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
             break;
     }
 }
 
Example 9
Source File: MainActivity.java    From Bitocle with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = MainActivity.this.getMenuInflater();
    inflater.inflate(R.menu.main_menu, menu);

    searchItem = menu.findItem(R.id.main_menu_add);
    searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setQueryHint(getString(R.string.main_menu_add_hint));
    searchItem.setVisible(false);

    return super.onCreateOptionsMenu(menu);
}
 
Example 10
Source File: DialtactsActivity.java    From coursera-android with MIT License 5 votes vote down vote up
private void prepareSearchView() {
    final View searchViewLayout =
            getLayoutInflater().inflate(R.layout.dialtacts_custom_action_bar, null);
    mSearchView = (SearchView) searchViewLayout.findViewById(R.id.search_view);
    mSearchView.setOnQueryTextListener(mPhoneSearchQueryTextListener);
    mSearchView.setOnCloseListener(mPhoneSearchCloseListener);
    // Since we're using a custom layout for showing SearchView instead of letting the
    // search menu icon do that job, we need to manually configure the View so it looks
    // "shown via search menu".
    // - it should be iconified by default
    // - it should not be iconified at this time
    // See also comments for onActionViewExpanded()/onActionViewCollapsed()
    mSearchView.setIconifiedByDefault(true);
    mSearchView.setQueryHint(getString(R.string.hint_findContacts));
    mSearchView.setIconified(false);
    mSearchView.setOnQueryTextFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (hasFocus) {
                showInputMethod(view.findFocus());
            }
        }
    });

    if (!ViewConfiguration.get(this).hasPermanentMenuKey()) {
        // Filter option menu should be shown on the right side of SearchView.
        final View filterOptionView = searchViewLayout.findViewById(R.id.search_option);
        filterOptionView.setVisibility(View.VISIBLE);
        filterOptionView.setOnClickListener(mFilterOptionClickListener);
    }

    getActionBar().setCustomView(searchViewLayout,
            new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}
 
Example 11
Source File: PlaybackActivity.java    From android-vlc-remote with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.playback_options, menu);            
    getMenuInflater().inflate(R.menu.playlist_options, menu);            
    getMenuInflater().inflate(R.menu.browse_options, menu);
    mSearchView = (SearchView) menu.findItem(R.id.menu_action_search).getActionView();
    mSearchView.setQueryHint(getString(R.string.action_search_title));
    if(mSearchViewOnQueryListener != null) {
        mSearchView.setOnQueryTextListener(mSearchViewOnQueryListener);
    }
    return true;
}