android menu code not working

后端 未结 1 943
无人共我
无人共我 2020-12-22 13:58

I have been trying to figure out why my boolean is not changing when I press the button, when I changed it manually it worked, but it doesn\'t do any thing. I have tried to

1条回答
  •  暖寄归人
    2020-12-22 14:02

    In res folder create one folder menu like drawable

    Create new xml file optionmenu.xml in that folder.

    
    
        
        
             
        
    
    
    
    

    In onCreate method write this code....

    setOptionMenu(R.menu.optionmenu);
    

    and in overide method of Menu write this code.....

    @Override
        public boolean onOptionsItemSelected(MenuItem menu) {
            switch (menu.getItemId()) {
            case R.id.menuitem:
                startActivity(new Intent(this, Prefs.class));
                break;
    
    case R.id.menuitem1:
                startActivity(new Intent(this, Prefs1.class));
                break;
            default:
                break;
            }
    
            return true;
        }
    

    0 讨论(0)
提交回复
热议问题