Example usage for android.view Menu findItem

List of usage examples for android.view Menu findItem

Introduction

In this page you can find the example usage for android.view Menu findItem.

Prototype

public MenuItem findItem(int id);

Source Link

Document

Return the menu item with a particular identifier.

Usage

From source file:de.geeksfactory.opacclient.frontend.AccountEditActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_account_edit, menu);
    if (getIntent().hasExtra("adding") && getIntent().getBooleanExtra("adding", false)) {
        menu.findItem(R.id.action_delete).setVisible(false);
    }/*from ww w. j  a  v a  2  s . c o m*/
    return super.onCreateOptionsMenu(menu);
}

From source file:com.bringcommunications.etherpay.SendActivity.java

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.send_options, menu);
    menu.findItem(R.id.show_gas).setChecked(show_gas);
    menu.findItem(R.id.show_data).setChecked(show_data);
    return (true);
}

From source file:org.ubicompforall.cityexplorer.gui.PoiDetailsActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();/*from ww w  .j a  va 2 s  . c  om*/
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.poi_menu, menu);
    if (poi.isFavorite()) {
        menu.findItem(R.id.poiMenufavorite).setIcon(R.drawable.favstar_on);
    } else {
        menu.findItem(R.id.poiMenufavorite).setIcon(R.drawable.favstar_off);
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:za.co.neilson.alarm.preferences.AlarmPreferencesActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    boolean result = super.onCreateOptionsMenu(menu);
    menu.findItem(R.id.menu_item_new).setVisible(false);
    return result;
}

From source file:com.akhbulatov.wordkeeper.ui.fragment.CategoryListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.fragment_category, menu);

    MenuItem searchItem = menu.findItem(R.id.menu_search_category);
    SearchView searchView = (SearchView) searchItem.getActionView();

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    searchView.setSearchableInfo(//from  w w w. j  a  v  a 2s . c  om
            searchManager.getSearchableInfo(new ComponentName(getActivity(), MainActivity.class)));
    searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            final Cursor cursor = mCategoryDbAdapter.getAll();
            final int column = cursor.getColumnIndex(CategoryEntry.COLUMN_NAME);
            if (newText.length() > 0) {
                mCategoryAdapter.swapCursor(new FilterCursorWrapper(cursor, newText, column));

                if (mCategoryAdapter.getItemCount() == 0) {
                    String escapedNewText = TextUtils.htmlEncode(newText);
                    String formattedNoResults = String.format(getString(R.string.no_results_category),
                            escapedNewText);
                    CharSequence styledNoResults = Html.fromHtml(formattedNoResults);

                    mTextNoResultsCategory.setText(styledNoResults);
                    mTextNoResultsCategory.setVisibility(View.VISIBLE);
                } else {
                    mTextNoResultsCategory.setVisibility(View.GONE);
                }
            } else {
                mCategoryAdapter.swapCursor(cursor);
                mTextNoResultsCategory.setVisibility(View.GONE);
            }
            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }
    });
}

From source file:com.maskyn.fileeditorpro.activity.SelectFileActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // menu items
    MenuItem imSetAsWorkingFolder = menu.findItem(R.id.im_set_as_working_folder);
    MenuItem imIsWorkingFolder = menu.findItem(R.id.im_is_working_folder);
    MenuItem imSelectFolder = menu.findItem(R.id.im_select_folder);
    if (imSetAsWorkingFolder != null) {
        // set the imSetAsWorkingFolder visible only if the two folder dont concide
        imSetAsWorkingFolder/* w  w  w .  j  av  a  2  s .co  m*/
                .setVisible(!currentFolder.equals(PreferenceHelper.getWorkingFolder(SelectFileActivity.this)));
    }
    if (imIsWorkingFolder != null) {
        // set visible is the other is invisible
        imIsWorkingFolder.setVisible(!imSetAsWorkingFolder.isVisible());
    }
    if (imSelectFolder != null) {
        imSelectFolder.setVisible(!wantAFile);
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:ca.rmen.android.poetassistant.main.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    Log.d(TAG, "onCreateOptionsMenu() called with: " + "menu = [" + menu + "]");
    getMenuInflater().inflate(R.menu.menu_main, menu);
    SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    mSearch.setSearchView(searchView);/* w  ww .  j a  v a 2 s  . c  om*/
    return super.onCreateOptionsMenu(menu);
}

From source file:com.alexandrepiveteau.filemanager.ui.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    mQuery = "";//from ww w  .j  a va2  s .c om

    mSearchView = (SearchView) menu.findItem(R.id.search).getActionView();
    mSearchView.setOnQueryTextListener(this);
    return true;
}

From source file:au.com.cybersearch2.classyfy.MainActivity.java

/**
 * Create search view SearchableInfo (xml/searchable.xml) and IconifiedByDefault (false)
 * @param menu Menu object//  w  w w . j  a  v  a  2  s. co  m
 */
protected void createSearchView(Menu menu) {
    /** Get the action view of the menu item whose id is action_search */

    // Associate searchable configuration (in res/xml/searchable.xml with the SearchView
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchMenuItem = menu.findItem(R.id.action_search);
    if (searchMenuItem == null)
        throw new IllegalStateException("Search menu item not found in main menu");
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
    if (searchView == null)
        throw new IllegalStateException("SearchView not found in main menu");
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
}

From source file:algolia.com.demo.moviesearch.ui.MovieSearchActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_movie_search, menu);

    // Configure search view.
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search));
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false);
    searchView.setOnQueryTextListener(this);

    return true;//  w ww  .java 2s.  c  om
}