Code example for Menu

Methods: findItem

    public boolean onPrepareOptionsMenu(Menu menu) {
        // Before showing the menu, we need to decide whether the clear 
        // item is enabled depending on whether there is text to clear. 
        menu.findItem(CLEAR_ID).setVisible(mEditor.getText().length() > 0);
        return true; 
     * Called when a menu item is selected. 
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case BACK_ID:
            return true; 
        case CLEAR_ID:
Contextual code suggestions in your IDE  Get Codota for Java