質問

I have a button in my screen and i want to open up the menuInflator when the button is pressed i tried the following code but it does not work

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        switch (arg0.getId()) {
          case R.id.btnmenu1:
            // TODO Auto-generated method stub
            MenuInflater inflatemenu = getMenuInflater();
            inflatemenu.inflate(R.menu.bmenu, menu);
            break;
 }

How do i make it work???

役に立ちましたか?

解決

Call openOptionsMenu(); method when click on button

or else set android:onClick="myOnClickMethod" on your Button in xml and then have:

public myOnClickMethod(View v) {
    openOptionsMenu();
}

in your activity.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top