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.example.haber.ui.activity.CallActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_call_activity, menu);
    MenuItem itemBW = menu.getItem(0);
    itemBW.setTitle("" + currentDefaultBW);
    return true;/*from  w  ww.  j a  v  a2 s  .co m*/
}

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    MenuItem item = menu.getItem(0);
    item.setEnabled(false);/*from  w  w w .j av  a2  s .c o m*/
    return true;
}

From source file:net.reichholf.dreamdroid.activities.ServiceListActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem overview = menu.getItem(2);

    if (mReference.equals("default")) {
        overview.setEnabled(false);/*from   w  w  w.j  a v  a 2 s  .c  om*/
    } else {
        overview.setEnabled(true);
    }

    MenuItem reload = menu.getItem(1);
    if (!mIsBouquetList && !mPickMode) {
        reload.setEnabled(true);
    } else {
        reload.setEnabled(false);
    }
    return true;
}

From source file:com.klinker.android.twitter.activities.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    if (settings.floatingCompose) {
        menu.getItem(2).setVisible(false); // hide the compose button here
    }//from w ww.  j  ava 2  s  .  c  o m

    if (settings.tweetmarkerManualOnly) {
        menu.getItem(7).setVisible(true);
    }

    return true;
}

From source file:com.sonnychen.aviationhk.MainActivity.java

private void bindUI() {

    List<CustomFragmentBase> fragments = new ArrayList<>();
    fragments.add(HomeFragment.newInstance(this));
    fragments.add(RadarFragment.newInstance(this));
    fragments.add(VHSKFragment.newInstance(this));
    fragments.add(MetarFragment.newInstance(this));
    fragments.add(LocalFragment.newInstance(this));

    mAdapter = new GenericViewPagerAdapter(fragments, this.getSupportFragmentManager());
    mViewPager.setAdapter(mAdapter);// w w w.  j a  v  a 2 s  . c o  m
    mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            // sync Bottom Navigation View
            Menu menu = mNavigation.getMenu();
            //                for (int i = 0; i < MainViewAdapter.NUM_ITEMS; i++) {
            //                    menu.getItem(i).setChecked(false);
            //                }
            menu.getItem(position).setChecked(true);

            // set page title
            MainActivity.this.setTitle(mAdapter.getPageTitle(position));
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

    //BottomNavigationViewHelper.disableShiftMode(mNavigation);
    mNavigation
            .setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {

                @Override
                public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                    switch (item.getItemId()) {
                    case R.id.navigation_home:
                        mViewPager.setCurrentItem(0);
                        return true;
                    case R.id.navigation_localaviation:
                        mViewPager.setCurrentItem(4);
                        return true;
                    case R.id.navigation_metartaf:
                        mViewPager.setCurrentItem(3);
                        return true;
                    case R.id.navigation_radar:
                        mViewPager.setCurrentItem(1);
                        return true;
                    case R.id.navigation_vhsk:
                        mViewPager.setCurrentItem(2);
                        return true;
                    }
                    return false;
                }

            });

    mLoading.setVisibility(View.GONE);
    mNavigation.setVisibility(View.VISIBLE);
    mViewPager.setVisibility(View.VISIBLE);

}

From source file:com.tweetlanes.android.core.view.TweetSpotlightActivity.java

void storeMenuItems(Menu menu) {
    for (int i = 0; i < menu.size(); i++) {
        MenuItem menuItem = menu.getItem(i);
        if (menuItem.getItemId() == R.id.action_favorite) {
            mFavoriteMenuItem = menuItem;
            setIsFavorited();// w w  w. j  a  v a 2  s.  c o  m
        }
        if (menuItem.getItemId() == R.id.action_retweet) {
            mRetweetMenuItem = menuItem;
            setIsRetweeted();
        }
    }
}

From source file:Windows.UI.Xaml.Controls.CommandBar.java

public void show(android.app.Activity activity, android.view.Menu menu) {
    //if (!(activity instanceof ActionBarActivity)) {
    android.app.ActionBar mainActionBar = activity.getActionBar();
    if (mainActionBar != null) {
        mainActionBar.show();/*from  w  ww  . ja v a  2  s.  c o m*/
        if (_primaryCommands != null) {
            for (int i = 0; i < _primaryCommands.size(); i++) {
                menu.add(0, i, 0, ((AppBarButton) _primaryCommands.get(i)).label);
                menu.getItem(i).setShowAsAction(android.view.MenuItem.SHOW_AS_ACTION_ALWAYS);
            }
        }
        return;
    }
    throw new RuntimeException(
            "Cannot use TabBar on the main page in Android unless you set <preference name=\"ShowTitle\" value=\"true\"/> in config.xml.");
    //}
    //else {
    //    ActionBar actionBar = ((ActionBarActivity)activity).getSupportActionBar();
    //    if (actionBar != null) {
    //        actionBar.show();
    //        for (int i = 0; i < _primaryCommands.size(); i++) {
    //            menu.add(0, i, 0, ((AppBarButton)_primaryCommands.get(i)).label);
    //            menu.getItem(i).setShowAsAction(android.view.MenuItem.SHOW_AS_ACTION_ALWAYS);
    //        }
    //        return;
    //    }
    //    throw new RuntimeException(
    //        "Unable to get the action bar from the current activity.");
    //}
}

From source file:com.offsec.nethunter.AppNavHomeActivity.java

@Override
public void onBackPressed() {
    super.onBackPressed();
    if (titles.size() > 1) {
        titles.pop();/*from  w w w.  j a  v a 2s. c om*/
        mTitle = titles.peek();
    }
    Menu menuNav = navigationView.getMenu();
    int i = 0;
    int mSize = menuNav.size();
    while (i < mSize) {
        if (menuNav.getItem(i).getTitle() == mTitle) {
            MenuItem _current = menuNav.getItem(i);
            if (lastSelected != _current) {
                //remove last
                lastSelected.setChecked(false);
                // udpate for the next
                lastSelected = _current;
            }
            //set checked
            _current.setChecked(true);
            i = mSize;
        }
        i++;
    }
    restoreActionBar();
}

From source file:edu.ucsb.cs.cs185.inspirante.collections.CardsFragment.java

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

    mMenu = menu;//w  w  w  .  j ava2s .  c  om

    super.onCreateOptionsMenu(menu, inflater);
    if (InboxCards.getInstance(getContext()).hasUnreadMessage()) {
        menu.getItem(1).setIcon(getResources().getDrawable(R.drawable.ic_new_mms_black_24dp));
    } else if (InboxCards.getInstance(getContext()).hasNoMessage()) {
        menu.getItem(1).setVisible(false);
    } else {
        menu.getItem(1).setVisible(true);
        menu.getItem(1).setIcon(getResources().getDrawable(R.drawable.ic_mms_black_24dp));
    }
}

From source file:io.tehtotalpwnage.musicphp_android.NavigationActivity.java

private int getCheckedItem(NavigationView navView) {
    Menu menu = navView.getMenu();
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        if (item.isChecked()) {
            return i;
        }//  w ww  .  j  av  a  2  s  .  co  m
    }

    return 0;
}