Example usage for android.view Menu getItem

List of usage examples for android.view Menu getItem

Introduction

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

Prototype

public MenuItem getItem(int index);

Source Link

Document

Gets the menu item at the given index.

Usage

From source file:no.group09.ucsoftwarestore.MainFragmentActivity.java

/**
 * Creates options menu// w  w w .j  a v a  2  s  .c o  m
 */
@SuppressLint("NewApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_menu, menu);

    //When the menu is created, check the preferences and set the correct text
    if (sharedPref.getBoolean("hide_incompatible", false)) {
        menu.getItem(1).setTitle("Hide incompatible");
        menu.getItem(1).setChecked(true);
    } else {
        menu.getItem(1).setTitle("Hide incompatible");
        menu.getItem(1).setChecked(false);
    }

    //Search bar for versions over API level 11
    int SDK_INT = android.os.Build.VERSION.SDK_INT;

    if (SDK_INT >= 11) {
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();

        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setSubmitButtonEnabled(true);
    }
    return true;
}

From source file:id.zelory.codepolitan.ui.ReadActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_read, menu);
    menuReadLater = menu.getItem(1);
    menuBookmark = menu.getItem(2);//from   w  w w .  j a  v  a 2 s  .  co  m
    menuReadLater.setChecked(articles.get(position).isReadLater());
    menuBookmark.setChecked(articles.get(position).isBookmarked());
    bookmarkController.setArticle(articles.get(position));
    readLaterController.setArticle(articles.get(position));
    return true;
}

From source file:com.esri.android.rt.map.PopupFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {

    // Turn on/off menu items based on popup's edit capabilities
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        if (mPopupContainer != null) {
            Popup popup = mPopupContainer.getCurrentPopup();
            if (popup != null) {
                if (popup.isEditMode()) {
                    if (item.getItemId() == R.id.menu_save || item.getItemId() == R.id.menu_camera) {
                        item.setVisible(true);
                        item.setEnabled(true);
                    } else {
                        item.setVisible(false);
                        item.setEnabled(false);
                    }//from   ww w.j av a  2  s .c  o  m
                } else {
                    if (((item.getItemId() == R.id.menu_edit) && (popup.isEditable()))
                            || ((item.getItemId() == R.id.menu_delete) && (popup.isDeletable()))) {
                        item.setVisible(true);
                        item.setEnabled(true);
                    } else {
                        item.setVisible(false);
                        item.setEnabled(false);
                    }
                }
            } else {
                item.setVisible(false);
                item.setEnabled(false);
            }
        } else {
            item.setVisible(false);
            item.setEnabled(false);
        }
    }
}

From source file:com.owncloud.android.files.FileMenuFilter.java

private void hideAll(Menu menu) {
    MenuItem item;/*  w  w w. j  ava  2 s  .c o  m*/
    for (int i = 0; i < menu.size(); i++) {
        item = menu.getItem(i);
        item.setVisible(false);
        item.setEnabled(false);
    }
}

From source file:com.activiti.android.app.activity.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    for (int i = 0; i < menu.size(); i++) {
        menu.getItem(i).setVisible(!mDrawerLayout.isDrawerOpen(mLeftDrawer));
    }//from w ww  . ja v  a  2s .c o  m
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.smsc.seguridad.ui.MenuActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (clsIncidentesDAO.Buscar(this) != null) {
        menu.getItem(0).setVisible(false);
        menu.getItem(1).setVisible(false);
        menu.getItem(2).setVisible(false);
    } else {/*from   www .java  2s.  co m*/
        menu.getItem(0).setVisible(true);
        menu.getItem(1).setVisible(true);
        menu.getItem(2).setVisible(true);
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.fsa.en.dron.activity.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    recargar = menu.getItem(0);
    if (NetworkUtils.isConnected(getApplication())) {
        recargar.setVisible(false);//from w  ww . ja v a2 s  .co m
        fetchImages();
    } else {
        recargar.setVisible(true);
    }

    return true;
}

From source file:com.artemchep.horario.ui.fragments.details.MooDetailsFragment.java

/**
 * Disables all menu items and the/*  w  w  w  .ja v a  2 s .co  m*/
 * {@link #mFab floating action button}.
 */
private void setMenuItemsEnabled(boolean enabled) {
    Menu menu = mToolbar.getMenu();
    int size = menu.size();
    for (int i = 0; i < size; i++) {
        menu.getItem(i).setEnabled(enabled);
    }

    mFab.setEnabled(enabled);
}

From source file:com.pepperonas.truthordare.fragments.FragmentMultiplayer.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    menu.add(0, 0, 0, "Start").setIcon(R.drawable.ic_marked_circle_white_24dp)
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    menu.getItem(0).setOnMenuItemClickListener(this);
}

From source file:org.horizonremote.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerContent);

    /* hide menu items when drawer is opened */

    int items = menu.size();
    for (int i = 0; i < items; ++i)
        menu.getItem(i).setVisible(!drawerOpen);

    return super.onPrepareOptionsMenu(menu);
}