This article describes the menu features in Android programming. Share to everyone for your reference, specific as follows:
Android Menu design, the program defines two menu subkeys, one is "about", one is "exit", when clicked on "about", a new toast prompt, when clicked "Exit", we will end the program.
In addition to the default coverage of OnCreate, you need to create another two class functions: Oncreateoptionsmenu () and onoptionsitemselected (), which is the item that creates the menu, The latter is the processing of events after the menu is selected to run.
Look at the effect chart:
We only make changes in one file, that is Menudemo.java, the code is as follows:
package com.android.test; import android.app.Activity; import Android.os.Bundle;
Import Android.view.Menu;
Import Android.view.MenuItem;
Import Android.widget.Toast; public class Menudemo extends activity {public void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstance
State);
Setcontentview (R.layout.main);
//Create Menus public boolean oncreateoptionsmenu (Menu menu) {menu.add (0, 0, 0, "about");
Menu.add (0, 1, 1, "exit");
return Super.oncreateoptionsmenu (menu);
}//Menu response public boolean onoptionsitemselected (MenuItem item) {super.onoptionsitemselected (item);
Switch (Item.getitemid ()) {case 0:toast.maketext (menudemo.this, "Welcome to the cloud-dwelling community", Toast.length_long). Show ();
Case 1:this.finish ();
return true; }
}
More interested readers of Android-related content can view the site: Android Development Primer and Advanced tutorials, the Android View View tips Summary, the activity tips summary of Android programming, Android Operation SQLite Database skills Summary, "Android operation JSON format Data Skills summary", "Android Database Operation skills Summary", "Android File Operation skills Summary", "Android programming development of SD card operation method Summary", " Android Resource Operation tips Summary and the "Android Controls usage Summary"
I hope this article will help you with the Android program.