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:br.com.GUI.aulas.Agenda.java

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

    final SearchView searchView = new SearchView(getActivity().getActionBar().getThemedContext());
    searchView.setQueryHint("Search");

    menu.add(Menu.NONE, Menu.NONE, 1, "@string").setIcon(android.R.drawable.ic_menu_search)
            .setActionView(searchView)//from www  .j a v  a2  s .  co m
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    searchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            if (newText.length() > 0) {
                // Search
                atualizarAgenda(newText.toString());

            } else {
                // Do something when there's no input
                atualizarAgenda(newText.toString());
            }
            return false;
        }

        @Override
        public boolean onQueryTextSubmit(String arg0) {
            // TODO Auto-generated method stub
            atualizarAgenda(arg0.toString());
            return false;
        }
    });
}

From source file:auribises.com.visitorbook.Activites.AdminEntryActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    menu.add(0, 101, 0, "All Visitors");

    return super.onCreateOptionsMenu(menu);
}

From source file:com.pansapiens.occyd.NewPost.java

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

    // group, id (for click handling), order, title
    int order = Menu.CATEGORY_CONTAINER + Menu.FLAG_ALWAYS_PERFORM_CLOSE;
    //menu.add(Menu.NONE, 0, order, "Search").setAlphabeticShortcut('s'); ;
    //menu.add(Menu.NONE, 1, order, "Post").setAlphabeticShortcut('p'); ;
    menu.add(Menu.NONE, 2, order, "Map").setAlphabeticShortcut('m');
    menu.add(Menu.NONE, 3, order, "Settings");
    menu.add(Menu.NONE, 4, order, "Help").setAlphabeticShortcut('h');
    return true;/*from  w  ww.  ja  va 2  s  .  co  m*/
}

From source file:com.scigames.slidegame.Registration1UserNameActivity.java

/**
 * Called when your activity's options menu needs to be created.
 *///from  ww w .  ja  v  a2 s  .  c o  m
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    // We are going to create two menus. Note that we assign them
    // unique integer IDs, labels from our string resources, and
    // given them shortcuts.
    menu.add(0, BACK_ID, 0, R.string.back).setShortcut('0', 'b');
    menu.add(0, CLEAR_ID, 0, R.string.clear).setShortcut('1', 'c');

    return true;
}

From source file:br.com.GUI.perfil.MeusAlunos.java

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

    final SearchView searchView = new SearchView(getActivity().getActionBar().getThemedContext());
    searchView.setQueryHint("Search");

    menu.add(Menu.NONE, Menu.NONE, 1, "@string").setIcon(android.R.drawable.ic_menu_search)
            .setActionView(searchView)//from   w ww. j  ava2 s  .  c o m
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    searchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            if (newText.length() > 0) {
                // Search
                atualizarMeusAlunos(newText.toString());

            } else {
                // Do something when there's no input
                atualizarMeusAlunos(newText.toString());
            }
            return false;
        }

        @Override
        public boolean onQueryTextSubmit(String arg0) {
            // TODO Auto-generated method stub
            atualizarMeusAlunos(arg0.toString());
            return false;
        }
    });
}

From source file:com.franmontiel.fullscreendialog.FullScreenDialogFragment.java

private void initToolbar(View view) {
    Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);

    Drawable closeDrawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_close);
    tintToolbarHomeButton(toolbar, closeDrawable);

    toolbar.setNavigationIcon(closeDrawable);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override/*from   w  w w  . j  a va 2s.c o  m*/
        public void onClick(View v) {
            onDiscardButtonClick();
        }
    });

    toolbar.setTitle(title);

    Menu menu = toolbar.getMenu();

    final int menuItemTitleId = 1;
    itemConfirmButton = menu.add(0, menuItemTitleId, 0, this.positiveButton);
    itemConfirmButton.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    itemConfirmButton.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (item.getItemId() == menuItemTitleId) {
                onConfirmButtonClick();
                return true;
            } else
                return false;
        }
    });
}

From source file:com.android.mms.rcs.FavoriteDetailActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();//from ww w . j  a v a2 s .co  m
    if (RcsDualSimMananger.getUserIsUseRcsPolicy(FavoriteDetailActivity.this)) {
        menu.add(0, MENU_FORWARD, 0, R.string.menu_forward);
    }
    if (!Contact.get(mMsgFrom, false).existsInDatabase()) {
        menu.add(0, MENU_SAVE_TO_CONTACT, 0, R.string.menu_add_to_contacts);
    }
    menu.add(0, MENU_UNFAVORITED, 0, R.string.unfavorited);
    return true;
}

From source file:net.olejon.mdapp.NotesEditActivity.java

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

    if (noteId != 0) {
        MenuItem menuItem = menu
                .add(Menu.NONE, Menu.NONE, Menu.NONE, getString(R.string.notes_edit_menu_delete))
                .setIcon(R.drawable.ic_delete_white_24dp);
        menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

        menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override/*from  w  w  w  .ja  v a  2 s.co m*/
            public boolean onMenuItemClick(MenuItem menuItem) {
                deleteNote(false);
                return true;
            }
        });
    }

    return true;
}

From source file:com.example.s_geomapsample.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.activity_main, menu);

    menu.add(0, MENU_A, 0, "Home");
    menu.add(0, MENU_B, 0, "Legal Notices");
    return true;/*www  .  j  a va  2 s . c o  m*/
}

From source file:name.setup.dance.DanceStepApp.java

public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();//from ww w.j a  v a 2 s.  co m
    if (mIsRunning) {
        menu.add(0, MENU_PAUSE, 0, R.string.pause).setIcon(android.R.drawable.ic_media_pause).setShortcut('1',
                'p');
    } else {
        menu.add(0, MENU_RESUME, 0, R.string.resume).setIcon(android.R.drawable.ic_media_play).setShortcut('1',
                'p');
    }
    menu.add(0, MENU_RESET, 0, R.string.reset).setIcon(android.R.drawable.ic_menu_close_clear_cancel)
            .setShortcut('2', 'r');
    menu.add(0, MENU_SETTINGS, 0, R.string.settings).setIcon(android.R.drawable.ic_menu_preferences)
            .setShortcut('8', 's').setIntent(new Intent(this, Settings.class));
    menu.add(0, MENU_QUIT, 0, R.string.quit).setIcon(android.R.drawable.ic_lock_power_off).setShortcut('9',
            'q');
    return true;
}