Android onCreateOptionsMenu change icon to enabled / disabled
<p>I want to be able in Android to press on the menu button on the phone and get the menu that will enable the user to toggle on/off sound. I want different images for the on/off status.</p>

<p>I know how to create menus; however, I'm having difficultly changing the menu button from one image to another. Has anyone figured this out?</p>

<p>Thanks</p>

<p>Below is my code :</p>

<p>@Override
  public boolean onCreateOptionsMenu(Menu menu) {</p>

<pre><code>  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.layout.menu, menu);

    return true;
</code></pre>

<p>}</p>

<p>public boolean onOptionsItemSelected(MenuItem item) {</p>

<pre><code>  // Handle item selection

  switch (item.getItemId()) {
  case R.id.EnableDisableSounds:

   if(musicflag == true)
   {  
   HighScores db = new HighScores(this);
   db.open();
   if(this.soundflag == true)
       db.insertSystem("1", "off", "on");
   else
    db.insertSystem("1", "off", "off");

   db.close();

   mp.pause();
      musicflag =  false;
   }
   else
   {
    HighScores db = new HighScores(this);
    db.open();
    if(this.soundflag == true)
        db.insertSystem("1", "on", "on");
    else
     db.insertSystem("1", "on", "off");

    db.close();

    mp.start();
    musicflag = true;
   }
    break;

  case R.id.EnableDisableMusic :
   if(soundflag == true) {

    HighScores db = new HighScores(this);
    db.open();

    if(this.musicflag == true)
        db.insertSystem("1", "on", "off");
    else 
     db.insertSystem("1", "off", "off");

    db.close();
       soundflag = false;
   }
   else if(soundflag == false) {
    HighScores db = new HighScores(this);
    db.open();

    if(this.musicflag == true)
        db.insertSystem("1", "on", "on");
    else
     db.insertSystem("1", "off", "on");

    db.close();
       soundflag = true;
   }

   break;
  case R.id.DeleteScores:
   HighScores db = new HighScores(this);
   db.open();
   db.DeleteDBTable();
   db.close();
   break;

  default:
      return super.onOptionsItemSelected(item);
  }

  return true;
</code></pre>

<p>}  </p>
