Example usage for android.view Menu add

List of usage examples for android.view Menu add

Introduction

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

Prototype

public MenuItem add(int groupId, int itemId, int order, @StringRes int titleRes);

Source Link

Document

Variation on #add(int,int,int,CharSequence) that takes a string resource identifier instead of the string itself.

Usage

From source file:gov.wa.wsdot.android.wsdot.ui.ferries.departures.FerriesRouteSchedulesDayDeparturesActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    MenuItem menuItem_Star = menu.add(0, MENU_ITEM_STAR, menu.size(), R.string.description_star);
    MenuItemCompat.setShowAsAction(menuItem_Star, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    if (mIsStarred) {
        menu.getItem(MENU_ITEM_STAR).setIcon(R.drawable.ic_menu_star_on);
        menu.getItem(MENU_ITEM_STAR).setTitle("Favorite checkbox, checked");
    } else {//from www .  j  av  a 2  s  .  com
        menu.getItem(MENU_ITEM_STAR).setIcon(R.drawable.ic_menu_star);
        menu.getItem(MENU_ITEM_STAR).setTitle("Favorite checkbox, not checked");
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:org.alfresco.mobile.android.application.fragments.preferences.AccountSettingsFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();//from w  ww . jav a 2s.c o  m
    MenuItem mi = menu.add(Menu.NONE, R.id.menu_account_delete, Menu.FIRST + 10, R.string.delete);
    mi.setIcon(R.drawable.ic_clear_grey);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    if (SessionManager.getInstance(getActivity()).hasSession(account.getId())) {
        mi = menu.add(Menu.NONE, R.id.my_profile, Menu.FIRST, R.string.my_profile);
        mi.setIcon(R.drawable.ic_account_circle_grey);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }
}

From source file:com.example.b1013029.myapplication.MapsActivity.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.main, menu);
    menu.add(0, MENU_A, 0, "Info");
    menu.add(0, MENU_B, 0, "Legal Notices");
    menu.add(0, MENU_C, 0, "Mode");
    return true;/* ww w .  j  a  v  a  2  s.  c  o  m*/
}

From source file:edu.stanford.mobisocial.dungbeetle.ui.fragments.FeedActionsFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem item;/*from   w  ww .java2 s .  com*/
    int placement = 0;
    Log.d(TAG, "creating menu " + mDualPane);
    if (mDualPane || MusubiBaseActivity.isDeveloperModeEnabled(getActivity())) {
        item = menu.add(0, MENU_VIEW, placement++, "View");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }
    }
    item = menu.add(0, MENU_SHARE, placement++, "Share");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

}

From source file:fm.libre.droid.LibreDroid.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem changeStation = menu.add(0, Menu.FIRST, 0, "Change Station").setIcon(R.drawable.back);
    MenuItem quit = menu.add(0, 2, 0, R.string.quit).setIcon(R.drawable.quit);
    changeStation.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            final ViewAnimator view = (ViewAnimator) findViewById(R.id.viewAnimator);
            if (view.getDisplayedChild() == 4) {
                LibreDroid.this.libreServiceConn.service.stop();
                LibreDroid.this.prevPage();
                LibreDroid.this.prevPage();
                LibreDroid.this.prevPage();
                return true;
            } else {
                return false;
            }/*w ww  .  ja  v  a 2 s . c  om*/
        }
    });

    quit.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            LibreDroid.this.libreServiceConn.service.stop();
            LibreDroid.this.finish();
            return true;
        }
    });

    return super.onCreateOptionsMenu(menu);
}

From source file:com.development.androrb.listfolders.java

private void populateMenu(Menu menu) {
    menu.add(Menu.NONE, ONE_ID, Menu.NONE, "Login Setup");
    //menu.add(Menu.NONE, BETA_ID, Menu.NONE, "ApiKey (Dev Mode)");
    menu.add(Menu.NONE, MAX_ID, Menu.NONE, "Max Items p.Page");
    menu.add(Menu.NONE, TWO_ID, Menu.NONE, "Help / About");
}

From source file:io.indy.drone.activity.StrikeListActivity.java

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

    if (AppConfig.DEBUG) {
        menu.add(Menu.NONE, mDebugMenuItemId, Menu.NONE, getString(R.string.temp_action_test));
    }/*from  w w w.  ja  v a2  s . c o m*/

    return super.onCreateOptionsMenu(menu);
}

From source file:com.application.treasurehunt.ScanQRCodeActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    //http://mobileorchard.com/android-app-development-menus-part-1-options-menu/
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.login, menu);
    menu.add(Menu.NONE, 1, Menu.NONE, "Home");
    menu.add(Menu.NONE, 2, Menu.NONE, "Log out");
    return true;//w w  w.j  a v  a2s  . co m
}

From source file:com.grarak.kerneladiutor.fragments.tools.customcontrols.CustomControlsFragment.java

private CardView getCard(final Controls.ControlItem controlItem) {
    CardView cardView = new CardView(getActivity());
    cardView.setOnMenuListener(new CardView.OnMenuListener() {

        @Override//w w w  . j  av  a 2s .  com
        public void onMenuReady(CardView cardView, PopupMenu popupMenu) {
            Menu menu = popupMenu.getMenu();
            menu.add(Menu.NONE, 0, Menu.NONE, getString(R.string.edit));
            final MenuItem onBoot = menu.add(Menu.NONE, 1, Menu.NONE, getString(R.string.on_boot))
                    .setCheckable(true);
            onBoot.setChecked(controlItem.isOnBootEnabled());
            menu.add(Menu.NONE, 2, Menu.NONE, getString(R.string.export));
            menu.add(Menu.NONE, 3, Menu.NONE, getString(R.string.delete));

            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                    case 0:
                        edit(controlItem);
                        break;
                    case 1:
                        onBoot.setChecked(!onBoot.isChecked());
                        controlItem.enableOnBoot(onBoot.isChecked());
                        mControlsProvider.commit();
                        break;
                    case 2:
                        mExportItem = controlItem;
                        requestPermission(0, Manifest.permission.WRITE_EXTERNAL_STORAGE);
                        break;
                    case 3:
                        mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.sure_question),
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                    }
                                }, new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        delete(controlItem.getUniqueId());
                                    }
                                }, new DialogInterface.OnDismissListener() {
                                    @Override
                                    public void onDismiss(DialogInterface dialog) {
                                        mDeleteDialog = null;
                                    }
                                }, getActivity()).setTitle(getString(R.string.delete));
                        mDeleteDialog.show();
                        break;
                    }
                    return false;
                }
            });
        }
    });
    return cardView;
}

From source file:com.mifos.mifosxdroid.online.SavingsAccountSummaryFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    menu.clear();/*from  w w w  .j a va  2 s  . co m*/
    menu.addSubMenu(Menu.NONE, MENU_ITEM_DATA_TABLES, Menu.NONE, Constants.DATA_TABLE_SAVINGS_ACCOUNTS_NAME);
    menu.add(Menu.NONE, MENU_ITEM_DOCUMENTS, Menu.NONE, getResources().getString(R.string.documents));

    // This is the ID of Each data table which will be used in onOptionsItemSelected Method
    int SUBMENU_ITEM_ID = 0;
    // Create a Sub Menu that holds a link to all data tables
    SubMenu dataTableSubMenu = menu.getItem(1).getSubMenu();
    if (dataTableSubMenu != null && savingsAccountDataTables != null && savingsAccountDataTables.size() > 0) {
        Iterator<DataTable> dataTableIterator = savingsAccountDataTables.iterator();
        while (dataTableIterator.hasNext()) {
            dataTableSubMenu.add(Menu.NONE, SUBMENU_ITEM_ID, Menu.NONE,
                    dataTableIterator.next().getRegisteredTableName());
            SUBMENU_ITEM_ID++;
        }
    }
    super.onPrepareOptionsMenu(menu);
}