Home > Android, Android how to, Menu > Creating Options Menu and adding menu items to the Options Menu in Android

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


We moved. Please visit this link for this post.

 

 

 

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.

@Override

public 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 see creating Options menu and adding menu items are simple operations.

Advertisements
Categories: Android, Android how to, Menu

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: