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:com.gbozza.android.popularmovies.fragments.MovieDetailFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.detail, menu);
    if (checkFavourite(mMovie.getId())) {
        menu.getItem(0).setIcon(R.drawable.ic_star);
    }//from ww  w.  jav a2 s  .  co  m
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.vuze.android.remote.activity.DrawerActivity.java

public boolean onPrepareOptionsMenu_drawer(Menu menu) {

    if (mDrawerLayout == null) {
        return true;
    }//from  w w  w. j av  a  2s .  c o  m

    if (!mDrawerLayout.isDrawerOpen(mDrawerView)) {
        for (int i = 0; i < menu.size(); i++) {
            MenuItem item = menu.getItem(i);
            item.setVisible(true);
        }
    } else {
        final int[] itemsToKeep = { R.id.action_about, R.id.action_logout, R.id.action_social,
                R.id.action_settings };
        for (int i = 0; i < menu.size(); i++) {
            MenuItem item = menu.getItem(i);
            int id = item.getItemId();
            boolean visible = false;
            for (int itemID : itemsToKeep) {
                if (id == itemID) {
                    visible = true;
                    break;
                }
            }
            item.setVisible(visible);
        }
        return false; // skip all other prepares
    }

    return true;
}

From source file:io.realm.scanner.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    final MenuItem item = menu.getItem(0);
    if (currentScan != null) {
        final String textScanResult = currentScan.getTextScanResult();
        final String classificationResult = currentScan.getClassificationResult();
        final String faceDetectionResult = currentScan.getFaceDetectionResult();
        if (textScanResult != null && classificationResult != null && faceDetectionResult != null) {
            item.setEnabled(true);//from   w w  w  . j a v  a  2  s  .c om
            return true;
        }
    }
    item.setEnabled(false);
    return true;
}

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

/**
 * Creates options menu/*from  w w  w  .ja  va  2  s. co  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:bander.notepad.NoteListAppCompat.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {

    ArrayList<Drawable> mTempList = new ArrayList<>();
    Log.i("Menu Size", menu.size() + "");
    for (int i = 0; i < menu.size(); i++) {
        mTempList.add(menu.getItem(i).getIcon());
    }//from  w w w  .  j a va  2 s  . c om
    final ArrayList<Drawable> mList;
    if (!PreferenceManager.getDefaultSharedPreferences(NoteListAppCompat.this).getBoolean("darkAppCompatTheme",
            false))
        mList = IconTintFactory.setDarkMaterialColor(mTempList, NoteListAppCompat.this);
    else
        mList = IconTintFactory.setLightMaterialColor(mTempList, NoteListAppCompat.this);
    for (int i = 0; i < menu.size(); i++) {
        if (mList.get(i) != null) {
            menu.getItem(i).setIcon(mList.get(i));
        }

    }

    return super.onPrepareOptionsMenu(menu);
}

From source file:com.heske.alexandria.activities.MainActivity.java

private void restoreNavPosition(int position) {
    Menu menu = mNavView.getMenu();
    menu.getItem(position).setChecked(true);
}

From source file:org.connectbot.EditHostActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(mIsCreating ? R.menu.edit_host_activity_add_menu : R.menu.edit_host_activity_edit_menu,
            menu);/*from  www  . j  av a2  s .co m*/

    mSaveHostButton = menu.getItem(0);

    // If the new host is being created, it can't be added until modifications have been made.
    setAddSaveButtonEnabled(!mIsCreating);

    return super.onCreateOptionsMenu(menu);
}

From source file:com.HACK.codersbestfriend.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);
    this.m_timerMenuItem = menu.getItem(0);
    return super.onCreateOptionsMenu(menu);
}

From source file:com.kccomy.orgar.ui.note.NoteFragment.java

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

    for (int i = 0; i < menu.size(); i++) {
        menu.getItem(i).setOnMenuItemClickListener(this);
    }//www. java  2 s. c o m
}

From source file:ua.com.spasetv.testintuitions.MainActivity.java

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.settings_menu, menu);
    getSettingsFromPreferences();//from  www.j  a v a  2 s.  c  o m
    menu.getItem(ITEM_SOUND).setChecked(is_sound);
    menu.getItem(ITEM_VIBRATE).setChecked(is_vibrate);
    return true;
}