如调用函数menu.add(0,ADD_ID,1, R.string.menu_add);
第一个参数表示菜单项的一个分组号,
第二个表示该菜单项的ID,
第三个参数的意义是顺序,编号越小越排在前面
最后一个表示应用的字符串资源的id。

菜单被分为如下三种,
选项菜单(OptionsMenu),
上下文菜单(ContextMenu),
子菜单(SubMenu)。

参考:[url]http://android.yaohuiji.com/archives/636[/url]

package com.mu;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class MenuActivity extends Activity {
private TextView textView1;
private Menu myMenu;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

textView1 = (TextView)findViewById(R.id.textView1);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
boolean result = super.onCreateOptionsMenu(menu);
int first = menu.FIRST;
menu.add(first, 1, 8, getString(R.string.group1));
menu.add(first, 2, 9,getString(R.string.group2));
menu.addSubMenu(1, 7, 1, "Sub Menu1");
menu.addSubMenu(1, 8, 2, "Sub Menu2");

//int secondary=Menu.CATEGORY_SECONDARY;
menu.add(2, 3, 4, "sec. 2item 3");
menu.add(2, 4, 3, "sec. 2item 4");

menu.add(3, 5, 5, "sec. 3item 5");
menu.add(3, 6, 6, "sec. 3item 6");

//menu.setGroupVisible(2, false);
//menu.setGroupVisible(3, false);

myMenu = menu;
return result;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
boolean result = super.onOptionsItemSelected(item);
textView1.setText("Menu ID="+item.getItemId());
/*if(1==item.getItemId()){
myMenu.setGroupVisible(2, true);
myMenu.setGroupVisible(3, false);
}
if(2==item.getItemId()){
myMenu.setGroupVisible(2, false);
myMenu.setGroupVisible(3, true);
}*/
return result;
}

@Override
public void onOptionsMenuClosed(Menu menu) {
// TODO Auto-generated method stub
super.onOptionsMenuClosed(menu);
//textView1.setText("onOptionsMenuClosed");
}
}