Menu Design Example _android of Android programming Basics

Source: Internet
Author: User
Tags sqlite database

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.