views:

37

answers:

1

Hello Folks! My problem is, that I have got a TabActivity, which has 4 Tabs right now. The first Tab is a special Details-Tab, where the user could modify some data.

The problem is, that if I add a OptionsMenu for the Activity, that the OptionsMenu is appearing on every Tab. I tried to check the current mTabHost.getCurrentTabTag() in the onCreateOptionsMenu but that changed nothing. So, how to do that?

(The following code, which still shows the OptionsMenu on every Tab)

 public boolean onCreateOptionsMenu(Menu menu) {    
  if(mTabHost.getCurrentTabTag()==getString(R.string.tab_details)) {
   boolean result = super.onCreateOptionsMenu(menu);
   menu.add(0, EDIT_ID, 0, R.string.menu_edit).setIcon(R.drawable.edit);
   return result;
  }    

  return true;
 }

 public boolean onMenuItemSelected(int featureId, MenuItem item) {
  switch (item.getItemId()) {
       case EDIT_ID: {   
        Toast.makeText(this, "o.O", Toast.LENGTH_LONG).show();   
       }
  }

  return super.onMenuItemSelected(featureId, item);
 } 
A: 

I see that you are comparing strings (tags in fact) with ==, usually, this is nicer to do that with .equals() method. Maybe it will solve your issue.
To dynamically update an option menu (from the documentation) :

If you want to change the Options Menu each time it opens, you must override the onPrepareOptionsMenu()

Sephy
Well, its nicer, but doesn't solve the problem. Because it rans into that IF all the time.
Keenora Fluffball
Actually, I'm not sure you can get an optionMenu which would be different on each tab, because, it is Activity specific. As you are staying in the same activity within your 4 tabs, the menu is the same. So you might want to use a context menu.
Sephy
Sorry didn't read the documentation properly. If you want to change the optionmenu everytime you open it, you need to use onPrepareOptionMenu and do the changes in it.
Sephy