How to Create a SubMenu:
Call the addSubMenu () method of Menu to add a sub-Menu.
Call the add () method of SubMenu,
Override the onContextItemSelected () method to respond to the Click Event of the sub-menu,
[Java] public class TestActivity extends Activity {
TextView textView;
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
TextView = (TextView) findViewById (R. id. textView1 );
}
Public boolean onCreateOptionsMenu (Menu menu ){
// Call the addSubMenu () method of Menu to add a sub Menu
SubMenu file = menu. addSubMenu ("file ");
SubMenu edit = menu. addSubMenu ("edit ");
// Add a sub-menu
File. add (0, Menu. FIRST + 1, 0, "new ");
File. add (0, Menu. FIRST + 2, 0, "open ");
Return true;
}
// Override the onContextItemSelected () method to respond to the Click Event of the sub-menu.
Public boolean onOptionsItemSelected (MenuItem item ){
If (item. getItemId () = Menu. FIRST + 1 ){
TextView. setText ("You selected" new "");
}
If (item. getItemId () = Menu. FIRST + 2 ){
TextView. setText ("You selected" open "");
}
Return true;
}
}
From Hu HU's column