Bart
Bart

Reputation: 29

Android: if this then change menu?

I want the options menu and its functions to change when I command it to.

So for example: layout is Fullscreen, options and quit. When I click on fullscreen, I want the menu to change so that it now looks like: Exit Fullscreen, options, quit.

I dont know everything in coding yet so I hope you can give some example code.

Thanks in advance!

this is the code for the menu:

 @Override
    public boolean onCreateOptionsMenu (Menu menu) {

     getMenuInflater().inflate (R.menu.menu, menu);
        return true;
    }



    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) 
        {

            case R.id.help:
                Intent intent = new Intent(this, help.class);
                startActivity(intent);
            break;

            case R.id.exitfullscreen:
                finish();  
            break;

            case R.id.quit:
                 moveTaskToBack(true);
            break;



            default:    
            break;
        }
        return false;

Upvotes: 1

Views: 123

Answers (1)

IAmGroot
IAmGroot

Reputation: 13855

Following your comments try this:

in your fullscreen.java

 @Override
    public boolean onCreateOptionsMenu (Menu menu) {

     getMenuInflater().inflate (R.menu.menu, menu);
        MenuItem mu = menu.findItem(R.id.exitfullscreen);
        mu.setTitle("Exit Full Screen");
        return true;
    }

P.S. Apply this where and when necssary to change your menu items text (title).

Upvotes: 1

Related Questions