android menus pdf

Document Sample
android menus pdf Powered By Docstoc

MENUS-1      Copyright © 2012,, All rights reserved

    • Menus are important parts of User Interface Activity.

    • Menus provides the users a familiar way to perform
      the actions.

    • Android provides a simple framework to add menus
      to your applications.

    • There are three types of application menus.
          • Options Menu
          • Context Menu
          • Sub Menu

MENUS-2                              Copyright © 2012,, All rights reserved

    • The primary collection of menu items for an activity,
      which appears when the user touches the MENU button.
    • Items in the OptionMenu are accessible in two ways:
           The MENU button.
           In the Action Bar. (on Android 3.0 or later ).
    • When running on a device with Android 2.3 or lower , the
      Options Menu appears at the bottom of the screen.
    • When opened , the first visible portion of the menu is
      icon menu.
    • It holds the first six menu items.
    • If you add more than six items to the options menu,
      Android places the sixth item and those after it into the
      overflow menu.

MENUS-3                                           Copyright © 2012,, All rights reserved
    • On Android 3.0 or higher , items from the Options
      Menu is placed in the action bar.
    • Action bar appears at the top of the activity in place
      of the traditional title bar.
    • By default all the items from the options menu are
      placed in the overflow menu, which the user can
      open by touching the menu icon on the right side of
      the Action bar.
    • However, you can place select menu items directly
      in the Action bar as “action items”, for instant

MENUS-4                              Copyright © 2012,, All rights reserved
                     Options Menu on emulator

 On Android 2.3 and lower

                             On Android 3.0 and higher

MENUS-5                                 Copyright © 2012,, All rights reserved
                                Creating Helper methods

    • Before creating options menu and context menu, we
      need to create two helper methods .
           One creates a list of items to show inside a menu.
           Second handles the event that is fired when the user selects
            an item inside the menu.
    • Creating OptionMenu:
           To create OptionsMenu first we need to override a method
           public boolean onCreateOptionsMenu(Menu m){}
           For adding menu items to the OptionsMenu we use the add()
            method with the following signature.
            add(int groupId, int itemid,int order, String title)
             groupId- The group identifier that the menu item should be part of.
              Use 0 if an item is not in a group
             itemId — Unique item ID
             order — The order in which the item should be displayed
             title — The text to display for the menu item

MENUS-6                                                     Copyright © 2012,, All rights reserved
    • You can use the setAlphabeticShortcut() method to
      assign a shortcut key to the menu item.
    • The setIcon() method sets an image to be displayed
      on the menu item.
    • The onOptionsItemSelected(MenuItem) method takes
      a MenuItem argument and checks its ID to determine
      the menu item that is clicked.

MENUS-7                            Copyright © 2012,, All rights reserved

  • Besides the options menu, you can also display a
    context menu.
  • A context menu is usually associated with a view on an
    activity, and it is displayed when the user long clicks an
  • For example, if the user taps on a Button view and hold
    it for a few seconds, a context menu can be displayed.
  • To create ContextMenu :
           Overriding onCreateContextMenu(ContextMenu menu, View v ,
            ContextMenuInfo menuinfo)
           Use add() method to add the menu items to the contextmenu.
           Overriding onContextItemSelected(MenuItem menuitem)

MENUS-8                                    Copyright © 2012,, All rights reserved

Description: Android tutorial with full Example, including Android UI Controls, layouts, Common application and Some FAQs, Android hello world example, android activity example, android source code to Eclipse IDE, button,textbox, password, checkbox, spinner,date picker, time picker, alert box, custom dialog, toast, imageview, imagebutton, LinearLayout, RelativeLayout, TableLayout, ListView, Gridview, Webview
PARTNER parameshwar kamani