Author Topic: how to create menus in android phone  (Read 309 times)

0 Members and 1 Guest are viewing this topic.

Offline emmytec4

  • Young Helper
  • ***
how to create menus in android phone
« on: February 05, 2014, 11:27:46 PM »
HOW TO CREATE MENUS IN ANDROID PHONES.  We can do it in: 1. Java code or  2.Using XML Method. Before we proceed further, let’s do it in the Java code, and the next in XML. through this way, we will see the differences and we can adopt the better way according to our programming styles. By Using the Menus in Java Codes Programming part, We need to add the following codes below in bold to our Activity, to create the Menu:  "public boolean onCreateOptionsMenu(Menu menu){ menu.add(0,EDIT_ CONTACT,0,”Edit Contact”); menu.add(0,DELETE_ CONTACT,0,”Delete Contact”); menu.add(0,EXIT,0,”Exit”); return true}. In the method add(),  we have four group argument id:  1.Group Arguement Id: With this parameter, we can associate this item with a group of others items.   2.Item Arguement Id: the ID unique item identifier.   3.Order Arguement Id: This number allows us to order the elements in the menu.   4.Title Arguement: This is the string that appears in the Menu Screen.   "public boolean onOptionsItemSelected (MenuItem item){ switch (item.getItemId()){ case EDIT_CONTACT: /* Actions in case that Edid Contacts is pressed */ return true case DELETE_CONTACT : /* Actions in case that Delete Contact is pressed */ return true }……return false }" . With the "onOptionsItemSelected method", we can control the actions of every item of the menu. In addition, we can put an Image or picture to each item in the Menu, to do this, we just need to add the following method cold in bold below to the menu.add() line:  "menu.add(0,EDIT_CONTACT, 0, “Edit”). setIcon(R.drawable.edit_ icon)" . The Menu icons are from a drawable resources. If our Android device has physical keyboard, we would like to add shortcuts to our menu. We can add an Alphabetic shorcut (with set Alphabetic Shorcut), or a numeric shorcut (with set Numeric Shortcut). Also, we can add both with “setShortcut” methods.   Lets see an example:  "menu.add(0,EDIT_ CONTACT,0,”edit”). setAlphabeticShortcut(‘e’)"; When “e” is pressed, the EDIT_ CONTACT option will be displayed. If you find the First Method a bit Technical, You can Try using the following codes:  "< ?xml version="1.0" encoding="utf-8"?>@Override public boolean onCreateOptionsMenu(Menu menu) {MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.game_ menu, menu); return true; }" . With the above android programming codes, you can program any sort of android menus and widget that has to do with arguements.   Alternative Rerources: Better still for Private Learning, You Can Get The Pdf Guide From Our Product Store at http://www.otechguide.com/store/products/android-programming-guide/ From Learning Android Application Programming: A Hands-On Guide to Building Android Applications From an Android developer.
http://www.otechguide.com

http://www.facebook.com/eisanandres

http://www.twitter.com/emmytec4

 

* Post Updates

WPX is giving out 6 months of free WordPress hosting this week by obasimiracle
[Today at 01:56:47 AM]


Re: Outlook PST Merge by ruth less
[November 11, 2020, 07:22:38 AM]


Re: How to Convert OLM to PST by priyankaarya
[November 10, 2020, 01:03:10 PM]

Inside: 3P Techies Blog

* Newest Techies

Get Updates


Sign up to get latest updates delivered to your inbox. No Spam, We Promise!

Get Hosting!

a Faster web hosting service

 

Copyright © 3rd Planet Techies. All rights Reserved.

Top || Mobile ||Advertise || Contact Us || Privacy