Creating Options Menu and adding menu items to the Options Menu in Android

From this post I am going to start series posts about Menu. Menu is very important. I will try to show all actions with menus in next posts.

Maybe it will be better to write one big article,but there are 2 problems from my side.

  1. Now I have no free time. All team works hard because we want to publish our updated applications in earlier November
  2. I like short but useful examples in manner how to

There are 3 types of menus:

  1. Options menus
  2. Context menus
  3. Sub menus

In this post I will show how to create Options menu and add menu items.

For creating need to override method onCreateOptionsMenu in Activity.

This code snippet shows how to create Options menu and add one menu item.

@Overridepublic boolean onCreateOptionsMenu(Menu menu){...menu.add(groupId,itemId,order,title);...return super.onCreateOptionsMenu(menu)}

Now I will add correct data.

Example:

menu.add(0, ITEM,0,"Menu item");

Second parameter is itemId. For it need to write:

private static final int ITEM = Menu.FIRST;

As you can see creating Options menu and adding menu items are simple operations.

Share

No related posts.

Leave a Reply

  

  

  

You can use these HTML tags

<a href=""title=""><abbr title=""><acronym title=""><b><blockquote cite=""><cite><code><del datetime=""><em><i><q cite=""><strike><strong>

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna,tincidunt vitae molestie nec,molestie at mi. Nulla nulla lorem,suscipit in posuere in,interdum non magna.