0

I'm trying to write code so that when a button is pressed, the dropdown menu in the navigation bar comes up. I tried making something similar to the following prefab function (which I understand to be the one responsible for opening the menu)

public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main_class, menu);
    return true;
}

Problem is that I don't know where they get the menu variable from. What should I put in it's place to complete the following function?

public void launchMenu(View view) {
    getMenuInflater().inflate(R.menu.main_class, (Menu) /* menu variable */);
}
user2824889
  • 1,085
  • 5
  • 16
  • 28

2 Answers2

0

Create this method in MainActivity which contains your navigation drawerLayout.

public void open()
{
    mDrawerLayout.openDrawer(Gravity.LEFT);
}

Check this SO question for more info.

Community
  • 1
  • 1
amalBit
  • 12,041
  • 6
  • 77
  • 94
0

I think you are looking for something like this...

public void showPopup(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.actions, popup.getMenu());
    popup.show();
}