..


Sponsored Links

Menu: What are OptionsMenu

A generic application worthy of this name should have a menu from which the user can choose between different tasks to perform. In this chapter, and those that follow, we will present the menu that Android provides us with learning how to handle the click on every menu item.

OptionsMenu

We start with presenting the OptionsMenu. This type of menu is positioned at the bottom of the screen and you can identify two main structures: the icon menu and expanded menu.

Expanded menus and icon menus

The Icon Menu usually contain the most important steps that a user can perform within the application. As stated are placed at the bottom of the screen and are visible to the user only after pressing the menu button on the device (this is also true on the simulator).

A widely used practice is to include in this menu of icons that summarize the result of which will be run at the click of the menu item. For example, if we refer to an application for playing music, you might think to associate with the play icon menu item associated with that transaction (the tringolino in a circle).

With regard to this menu we have a limitation on the number of entries you can enter and this number is six. But what happens if we insert a number of items more than six? just the sixth menu item will be changed into an item that when clicked will open a much expanded menu with other items. The latter will appear in a list that will expand to full screen from the bottom up gradually going to cover the basic content of the Activity window.

That said it should show a little 'code (to be included in our activity) that will create an Options menu that will be formed by Icon Menu and Expanded menu (You must first import the class android.view.Menu) :






 public void onCreate (Bundle savedInstanceState) {



  



 super.onCreate (savedInstanceState);



  



 LinearLayout LinearLayout LinearLayout = new (this);



  



 TextView TextView = new TextView (this);



  



 textView.setText ("Click on the menu of the simulator");



  



 linearLayout.addView (TextView);



  



 setContentView (LinearLayout);

   





 }









 public boolean onCreateOptionsMenu (Menu menu) {

 

  



 menu.add (Menu.NONE, 1, 1, "Item 1");



  



 menu.add (Menu.NONE, 2, 2, "Item 2");

 

  



 menu.add (Menu.NONE, 3, 3, "Item 3");

 

  



 menu.add (Menu.NONE, 4, 4, "Item 4");



  



 menu.add (Menu.NONE, 5, 5, "Item 5");



  



 menu.add (Menu.NONE, 6, 6, "Item 6");

 

  



 menu.add (Menu.NONE, 7, 7, "Item 7");

 

  



 menu.add (Menu.NONE, 8, 8, "Item 8");

 

  



 return true;







 }



As mentioned above, if we click on the menu of the simulator will make visible the icon menu shown in the screenshot below:

Example IconMenu.

In agreement with what was said, since we have entered a number of items more than six, the last entry will be the access point Expanded menu that you can see in this screnshot:

Example ExpandedMenu.

As we can see once you click any of the items in the menu, it will return silently.

In the next chapter we will analyze the code and presented to listeners will associate a particular menu items.

Help develop applications for Android
E-Learning
Front Page (Ebook) Front Page (Ebook)
Create Web pages without knowing HTML. Just 25 €.
VB.NET (Course) VB.NET (Course)
Make Desktop Applications with Visual Basic.. From 49 €.
XML (Course) XML (Course)
Creation of XML structures, XSL and other languages ​​extensible. Starting from 29 €.
Sponsored Links