Friday, May 31, 2013

Create Option Menu In Android

Option Menu:
Option Menu is a drop down menu containing   options, and appears when a users clicks on Menu button.
For Ex:

We can create an Option Menu with following :
  1. Create a menu xml
  2. Register the menu in Activity
  3. Write code to Handle the Clicks on menu items

1: Create xml for menu

     Create a new folder named "Menu" in res folder
     inside this  Menu folder create .xml    file

here I have created option.xml   xml for the option menu in  above  Image

           <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="" >
     <item android:id="@+id/ChangeColor"
    <item android:id="@+id/phoneInformation"
          android:title="My Phone Information" />
    <item android:id="@+id/callInfo"
          android:title="In and Out Call Info" />

    <item android:id="@+id/email"
          android:title="Mail to Developer" />

A resource ID that's unique to the item, which allows the application can recognize the item when the user selects it.
An image  to use as the item's icon.
A tittle to show.

2: Register In Activity

Override onCreateOptionMenu   method and inflate the .xml (here options.xml) inside method

                     public boolean onCreateOptionsMenu(Menu menu) {
                            MenuInflater inflater = getMenuInflater();
                            inflater.inflate(, menu);
                            return true;

3: Handle Click Events

When the user selects an item from the options menu (including action items in the action bar), the system calls your activity's onOptionsItemSelected() method. This method passes the MenuItem selected. You can identify the item by calling getItemId(), which returns the unique ID for the menu item (defined by the android:id attribute in the menu resource

 To Handle click events override  onOptionsItemSelected  method

                     public boolean onOptionsItemSelected(MenuItem item) {
                         // Handle item selection
                         switch (item.getItemId()) {
                                                              // write code to execute when clicked on this option
                                                                return true;   

                                                             // write code to execute when clicked on this option
                                                             return true;
                                                              // write code to execute when clicked on this option
                                                             return true;
                                                            // write code to execute when clicked on this option
                                                              return true;
                                                   return super.onOptionsItemSelected(item);

Advance Android Topics

                   Customizing Toast In Android 
                   Showing Toast for Longer Time
                   Customizing the Display Time of Toast
                   Using TimePickerDialog and DatePickerDialog In android
                   Animating A Button In Android
                    Populating ListView With DataBase

                    Customizing Checkboxes In Android 
                    Increasin Size of Checkboxes
                    Android ProgressBar
                    Designing For Different Screen Sizes
                    Handling Keyboard Events

 More Android Topics

Android : Introduction

       Eclipse Setup for Android Development

                     Configuring Eclipse for Android Development

          Begging With Android

                     Creating Your First Android Project
                     Understanding Android Manifest File of your android app

         Working With Layouts

                      Understanding Layouts in Android
                          Working with Linear Layout (With Example)
                                Nested Linear Layout (With Example)
                          Table Layout
                          Frame Layout(With Example)
                         Absolute Layout
                         Grid Layout


                     Activity In Android
                     Activity Life Cycle
                     Starting Activity For Result
                     Sending Data from One Activity to Other in Android
                     Returning Result from Activity

     Working With Views

                     Using Buttons and EditText in Android 
                     Using CheckBoxes in Android 
                     Using AutoCompleteTextView in Android
                     Grid View


                     Customizing Toast In Android
                     Customizing the Display Time of Toast
                     Customizing Toast At Runtime
                     Adding Image in Toast
                     Showing Toast for Longer Time

     Dialogs In Android

                     Working With Alert Dialog
                     Adding Radio Buttons In Dialog
                     Adding Check Boxes In Dialog
                     Creating Customized Dialogs in Android
                    Adding EditText in Dialog

                   Creating Dialog To Collect User Input

                 DatePicker and TimePickerDialog

                              Using TimePickerDialog and DatePickerDialog In android

    Working With SMS

                  How to Send SMS in Android
                  How To Receive SMS
                  Accessing Inbox In Android


               Populating ListView With DataBase

      Menus In Android

                    Creating Option Menu
                    Creating Context Menu In Android


                    Using Telephony Manager In Android

     Working With Incoming Calls

                    How To Handle Incoming Calls in Android
                    How to Forward an Incoming Call In Android
                   CALL States In Android


                   Notifications In Android
                   How To Vibrate The Android Phone
                   Sending Email In Android
                  Opening a webpage In Browser
                   How to Access PhoneBook In Android
                   Prompt User Input with an AlertDialog

   Storage:  Storing Data In Android

               Shared Prefferences  In Android

                             SharedPreferences In Android

               Files: File Handling In Android

                              Reading and Writing files to Internal Stoarage
                              Reading and Writing files to SD Card 

                DataBase : Working With Database

                             Working With Database in Android
                             Creating Table In Android
                             Inserting, Deleting and Updating Records In Table in Android
                             How to Create DataBase in Android
                             Accessing Inbox In Android

     Animation In Android:

                  Animating A Button In Android


No comments:

Post a Comment