move Sub Menu - Android User Interface

Android examples for User Interface:Menu

Description

move Sub Menu

Demo Code


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

public class Main {
    public static void mov2SubMenu(Menu menue, String subMenue,
            int... ids2move) {
        if (menue != null) {
            SubMenu subMenu = menue.addSubMenu(Menu.NONE, Menu.NONE, 32767,
                    subMenue);//from  w  w  w .  j  a  va 2s .  co m

            for (int idSub : ids2move) {
                MenuItem oldMenuItem = menue.findItem(idSub);

                if (oldMenuItem != null) {
                    menue.removeItem(idSub);
                    menue.removeItem(idSub);
                    menue.removeItem(idSub);
                    MenuItem newMenuItem = subMenu.add(
                            oldMenuItem.getGroupId(),
                            oldMenuItem.getItemId(),
                            oldMenuItem.getOrder(), oldMenuItem.getTitle());
                    newMenuItem.setCheckable(oldMenuItem.isCheckable());
                    newMenuItem.setVisible(oldMenuItem.isVisible());
                }
            }
        }
    }
}

Related Tutorials