create Menu Item - Android User Interface

Android examples for User Interface:Menu

Description

create Menu Item

Demo Code


//package com.java2s;
import android.view.Menu;
import android.view.MenuItem;

public class Main {
    static public MenuItem createMenuItem(final Menu menu,
            final int itemId, final int order, final int iconId) {
        final MenuItem item = menu.findItem(itemId);
        if (item != null)
            return item;
        final MenuItem newItem = menu.add(0, itemId, order, itemId);
        if (iconId != 0)
            newItem.setIcon(iconId);//from   w ww  .  j a v  a  2 s.  c  om
        return newItem;
    }

    static public MenuItem createMenuItem(final Menu menu, final int itemId) {
        final MenuItem item = menu.findItem(itemId);
        if (item != null)
            return item;
        return menu.add(0, itemId, Menu.NONE, itemId);
    }
}

Related Tutorials