Alex Bond Alex Bond - 1 year ago 116
Android Question

How to add an options menu to the menu Button

I want to add a menu on the left click.

Where to read about how to do this?

for this button

Here is the menu

public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Context Menu");
menu.add(0, v.getId(), 0, "Action 1");
menu.add(0, v.getId(), 0, "Action 2");
menu.add(0, v.getId(), 0, "Action 3");

public boolean onContextItemSelected(MenuItem item) {
if (item.getTitle() == "Action 1") {
Toast.makeText(this, "Action 1 invoked", Toast.LENGTH_SHORT).show();
else if (item.getTitle() == "Action 2") {
Toast.makeText(this, "Action 2 invoked", Toast.LENGTH_SHORT).show();
else if (item.getTitle() == "Action 3") {
Toast.makeText(this, "Action 3 invoked", Toast.LENGTH_SHORT).show();
else {
return false;
return true;

Now I deduce it by pressing the button in the Activiti

Button btn = (Button) findViewById(;

And I want to display when user click on a selection button in the image.

How to do it?

Answer Source

You can find information here.

I think you are looking for an options menu. But above Android 3.0 the context menu is in the actionbar.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download