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:br.com.android.cotuca.toptask.Activitys.MSimplesActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // se o Drawer menu esta aberto ocultar os icones da actionBar

    boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
    menu.findItem(R.id.action_add).setVisible(!drawerOpen);
    return super.onPrepareOptionsMenu(menu);
}

From source file:blackman.matt.infinitebrowser.InfinityBrowser.java

/**
 * Sets up the options menu./*  w w  w.j  a  v  a 2  s . co m*/
 * @param menu The menu being created
 * @return If the action was a success
 */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    boolean result = super.onPrepareOptionsMenu(menu);
    menu.findItem(R.id.action_settings).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            InfinityBrowser.this.startActivity(new Intent(InfinityBrowser.this, SettingsActivity.class));
            return true;
        }
    });
    return result;
}

From source file:com.adkdevelopment.e_contact.ui.MainActivity.java

/**
 * Updated buttons in the Navigation Drawer according to a state
 *//*from w  w w .  j a  va  2  s  . c o  m*/
private void updateDrawer() {
    // select first item in navigation drawer on startup
    Menu drawerMenu = mNavigationView.getMenu();
    drawerMenu.getItem(0).setChecked(true);

    // set correct visibility of we are logged in or logged out
    MenuItem facebookProfile = drawerMenu.findItem(R.id.profile_button);
    MenuItem login = drawerMenu.findItem(R.id.login_button);
    if (facebookProfile != null) {
        if (AccessToken.getCurrentAccessToken() != null) {
            login.setVisible(false);
            facebookProfile.setVisible(true);
        } else {
            login.setVisible(true);
            facebookProfile.setVisible(false);
        }
    }
}

From source file:com.sudhirkhanger.app.popularmoviesstageone.TitlesFragment.java

/**
 * When a user makes a choice between//  w  w  w  .j  a  v  a  2  s.c om
 * sorting choices we also want to update
 * the selection in menu ui.
 *
 * @param menu
 */
@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    String sortBy = mSettings.getString(SHARED_KEY_SORT, POPULARITY);
    if (sortBy.equals(POPULARITY)) {
        menu.findItem(R.id.popularity).setChecked(true);
    } else {
        menu.findItem(R.id.rating).setChecked(true);
    }
}

From source file:ca.ualberta.cmput301w14t08.geochan.fragments.EditFragment.java

/**
 * Creates and initialzes the menu of the fragment. Called only by Android.
 * //from   w  w w. j  av  a 2 s . co  m
 * @param menu The Menu object for the fragment.
 * @param inflater The inflater for the menu.
 */
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // Inflate the menu; this adds items to the action bar if it is present.
    MenuItem item = menu.findItem(R.id.action_settings);
    item.setVisible(true);
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:butter.droid.activities.MainActivity.java

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

    MenuItem playerTestMenuItem = menu.findItem(R.id.action_playertests);
    playerTestMenuItem.setVisible(Constants.DEBUG_ENABLED);

    return true;/*  w ww.  j  a v a2  s  .c o  m*/
}

From source file:com.abhijitvalluri.android.fitnotifications.AppChoicesActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem searchItem = menu.findItem(R.id.menu_app_search);
    MenuItem filterEnabledItem = menu.findItem(R.id.menu_filter_enabled);

    if (mAdapter == null) { // cannot search yet
        searchItem.setEnabled(false);//from   w  w w.j  ava2  s  .co m
        filterEnabledItem.setEnabled(false);
    } else {
        searchItem.setEnabled(true);
        filterEnabledItem.setEnabled(true);
    }

    return true;
}

From source file:net.eledge.android.europeana.gui.activity.RecordActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (mDrawerLayout != null) {
        boolean drawerOpen = mDrawerLayout.isDrawerOpen(mResultsList);
        menu.findItem(R.id.action_share).setVisible(!drawerOpen);
        if (drawerOpen && (searchController.getItemSelected() != -1)) {
            mResultsList.smoothScrollToPosition(searchController.getItemSelected());
        }/* w w w  .ja  v a  2  s .  c o  m*/
    }
    menu.findItem(R.id.action_previous).setVisible(searchController.hasPrevious());
    menu.findItem(R.id.action_next).setVisible(searchController.hasNext());
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.hybris.mobile.activity.StoreLocatorDetailActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = this.getMenuInflater();
    inflater.inflate(R.menu.store_details, menu);

    MenuItem geofenceItem = menu.findItem(R.id.geofence_store);

    // We display an active icon if there is a geofence for this store AND the geofencing functionnality is activated
    if (geofenceJsonSharedPreferences.getGeofenceObject(store.getName()) != null
            && Hybris.isGeofencingActivated()) {
        geofenceItem.setIcon(R.drawable.ic_menu_location_active);
    }/* w  ww. j a  v  a 2  s. c o m*/
    // Otherwise we display the default icon
    else {
        geofenceItem.setIcon(R.drawable.ic_menu_location_default);
    }

    return true;
}

From source file:ca.ualberta.cmput301w14t08.geochan.fragments.ThreadListFragment.java

/**
 * Sets the user selected sorting option in our options menu.
 * @param sort Code for the type of sort being used.
 * @param menu The fragment's menu./*from  w  ww.j a v  a2s  .com*/
 */
private void setSortCheck(int sort, Menu menu) {
    MenuItem item;
    switch (sort) {
    case SortUtil.SORT_DATE_NEWEST:
        item = menu.findItem(R.id.thread_sort_date_new);
        item.setChecked(true);
        return;
    case SortUtil.SORT_DATE_OLDEST:
        item = menu.findItem(R.id.thread_sort_date_new);
        item.setChecked(true);
        return;
    case SortUtil.SORT_LOCATION:
        item = menu.findItem(R.id.thread_sort_location);
        item.setChecked(true);
        return;
    case SortUtil.SORT_USER_SCORE_HIGHEST:
        item = menu.findItem(R.id.thread_sort_score_high);
        item.setChecked(true);
        return;
    case SortUtil.SORT_USER_SCORE_LOWEST:
        item = menu.findItem(R.id.thread_sort_score_low);
        item.setChecked(true);
        return;
    default:
        return;
    }
}