chapter4_ menu (XML & add)

2010-12-27  来源:本站原创  分类:Mobile  人气:116 

package com.yarin.android.Examples_04_13;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

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

        /* Create menu*/
        public boolean onCreateOptionsMenu(Menu menu)
        {
                MenuInflater inflater = getMenuInflater();
                // Set the menu interface for res/menu/menu.xml
                inflater.inflate(R.menu.menu, menu);
                return true;
        }

        /* Handle menu events */
        public boolean onOptionsItemSelected(MenuItem item)
        {
                // Get the currently selected MenuItem ID,
                int item_id = item.getItemId();

                switch (item_id)
                {
                        case R.id.about:
                                /*  Create a new Intent object  */
                                Intent intent = new Intent();
                                /*  Specifies the intent to start class  */
                                intent.setClass(Activity01.this, Activity02.class);
                                /*  Start a new Activity */
                                startActivity(intent);
                                /*  Closes the current Activity */
                                Activity01.this.finish();
                                break;
                        case R.id.exit:
                                Activity01.this.finish();
                                break;
                }
                return true;
        }
}

package com.yarin.android.Examples_04_13;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class Activity02 extends Activity
{
        public void onCreate(Bundle savedInstanceState)
        {
                super.onCreate(savedInstanceState);
                /*  Set display main2.xml layout  */
                setContentView(R.layout.main2);
        }

        /* Create menu*/
        public boolean onCreateOptionsMenu(Menu menu)
        {
                // Add content to menu
                menu.add(0, 0, 0, R.string.ok);
                menu.add(0, 1, 1, R.string.back);
                return true;
        }

        /* Handling the events menu */
        public boolean onOptionsItemSelected(MenuItem item)
        {
                // Get the currently selected MenuItem ID,
                int item_id = item.getItemId();

                switch (item_id)
                {
                        case 0:
                        case 1:
                                /*  Create a new Intent object  */
                                Intent intent = new Intent();
                                /*  Specifies the intent to start class  */
                                intent.setClass(Activity02.this, Activity01.class);
                                /*  Start a new Activity */
                                startActivity(intent);
                                /*  Closes the current Activity */
                                Activity02.this.finish();
                                break;
                }
                return true;
        }
}

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/about"
          android:title=" About " />
    <item android:id="@+id/exit"
          android:title=" Exit " />
</menu>

chapter4_ menu (XML & add)

相关文章
  • chapter4_ menu (XML & add) 2010-12-27

    package com.yarin.android.Examples_04_13; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; public class Activity01 extends

  • dhtmlxtree right menu to add, delete, modify 2010-09-03

    dhtmlxtree right menu to add, delete, modify the concrete realization

  • In the context menu to add Ubuntu terminal part 2011-08-28

    There may be many people from RedHat to Ubuntu and other Linux distributions to the above first encountered one of the most common problem is, right-click the desktop and found that there is no "open terminal" option, here are two ways to add th

  • menu.addIntentOptions add dynamic menu 2010-03-20

    android can then select an activity menu key press after a specific pop-up menu, which is dynamic menu. Implementation of a dynamic menu by menu class addIntentOptions function implementation, the specific statement as follows: int android.view.Menu.

  • Desktop Launcher Simulation Research Press Menu to add features and functions 2010-10-19

    <! - [If! Mso]> <style> v \: * {behavior: url (# default # VML);} o \: * {behavior: url (# default # VML);} w \: * { behavior: url (# default # VML);}. shape {behavior: url (# default # VML);} </ style> <! [endif ]--><!-- [if gt

  • Detailed menu.addIntentOptions add dynamic menu 2010-11-16

    An android activity can then press the menu button then select a specific pop-up menu, which is dynamic menu. Implementation of a dynamic menu by menu class addIntentOptions function implementation, the specific statement as follows: int android.view

  • swing pop-up menu to add the container (jbutton, jlabel more space) 2011-01-14

    Adding Menu Items to a JPopupMenu public JMenuItem add (JMenuItem menuItem); public JMenuItem add (String label); public JMenuItem add (Action action); public void addSeparator (); import javax.swing.JButton; import javax.swing.JFrame; import javax.s

  • drupal in the navigation menu to add | characters 2010-09-08

    Copy and paste the theme_links function from theme.inc to your template.php file. Change the name of the function to YOURTHEME_links where YOURTHEME is the name of your theme. Add the following code snippet on the second line of the function, after t

  • Custom right click menu (load xml file) 2010-09-13

    By loading the external xml file data, customize the context menu. xml file (setup.xml) <?xml version="1.0" encoding="UTF-8"?> <shell> <menu> <item url="http://www.baidu.com"> Visit Baidu </item>

  • The status bar at the android (statusbar) to add menu, home and way back shortcut 2010-11-15

    Completely changed the status bar, recommend a few png images, add Frameworks / base / core / res / res / drawable Next. Best to do a background image, replace statusbar_background.png In addition, I added a few icon, is the home menu, and back were

  • The status bar at the android (statusbar) to add menu, home and back shortcuts Improvement 2010-11-19

    http://blog.csdn.net/freshui/archive/2010/07/15/5738115.aspx Should be noted that: just a few days to start android, not too familiar with the system, this article is based on a Zhuantie done before. Just think of his method some trouble, but the eff

  • Swing to the menu button to add shortcut keys 2010-03-29

    package Assis; import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.SwingUtilities; public class Sketcher { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { creatGUI(); } }); }

  • The use of XML / HTC / DHTML analog standard Windows menu 2010-01-09

    With the internet's development, XML as a cross-platform common structured data description language become more and more people's attention, and has been widely used, such as the MicroMedia companies produce go Dreamweaver, Flash, and games have mad

  • asp.net on the xml file read and write, add, modify, delete operations 2010-03-29

    asp.net on the xml file read and write, add, modify, delete operations have the following code to debug the correct using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using

  • WP to add a custom menu theme, example application BlueSpeech 2011-01-12

    Source: http://blog.yation.com/webpro/wp_nav_menu/ According to statistics, WP installation of the number of similar and related products is far ahead, see WP number of users as much relevant information and help files are quite complete. I am also a

  • java jtree on different nodes of different ways to add menu 2011-04-29

    java jtree on different nodes of different ways to add menu 2010-04-26 16:04 To address this issue, I think for a long time, but also searched for information from the Internet, but it seems that no complete solution. Then I thought of a party Method

  • Menu Big Face 2010-03-29

    Tell the truth in relation to personal feelings Memu really ugly, so try to replace today's [Principle] 1. Retain Menu buttons work 2. With the ListView display all sub-menu [Code Step] 1. Menu.xml definition contains only a ListView and get the View

  • Chapter VIII of the list. Menu, as well as other view - on the 2010-03-29

    Key skills and concepts l Construction Activity l Use Android Menu l Use AutoCompleteTextView This chapter of the Views and Intents to do an in-depth research, which is for the novice Android need to know the most important features. The two entities

  • Chapter VIII of the list. Menu and other view - the 2010-03-19

    Key skills and concepts l Construction Activity l use Android Menu l use AutoCompleteTextView This chapter of the Views and Intents to do in-depth study of these newcomers for Android is to master the most important features. The two entities formed

  • With icon shortcuts Menu - Ultimate Edition 2010-05-04

    Menu enhancement 1. Icon text of 2. Xp shortcut menu for more details refer to [Code Step] 1. Define a template used to load the text and the corresponding interfaces shortcut icon public class IconifiedTextItem { String text; Drawable icon; String s