Code example for Menu

Methods: findItem

0
    public boolean onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(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. 
     */ 
    @Override 
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case BACK_ID:
            finish();
            return true; 
        case CLEAR_ID:
Stop searching for code, let great code find you!  Add Codota to your java IDE