The example of this article describes the implementation of menu key function of Android programming. Share to everyone for your reference. The specific analysis is as follows:
The Android app can eject a menu with menu keys and now pops a menu with two options through the Menus button. Click on the first button, the text box will display the "1th button", click the second button, the text box will display "2nd button"
Package com.test_menu;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.view.Menu;
Import android.view.*;
import android.widget.*;;
public class Test_menu extends activity {public static final int ITEM0 = Menu.first;
public static final int ITEM1 = Menu.first + 1;
private TextView text; /** called the activity is a.
* * @Override public void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Text = (TextView) Findviewbyid (R.ID.TEXTVIEW1);
@Override public boolean Oncreateoptionsmenu (Menu menu) {super.oncreateoptionsmenu (menu);
Menu.add (0,item0,0, "Button1");
Menu.add (0,item1,0, "button2");
Menu.finditem (ITEM1);
return true; public boolean onoptionsitemselected (MenuItem item) {switch (Item.getitemid ()) {case ITEM0: {Text.settex
T ("1th button");
Break
Case ITEM1: {text.settext ("2nd button");
Break } return super.onoptionsitemselected (iTEM); }
}
Run Effect chart:
I hope this article will help you with your Android program.