开发者

Optionsmenu in an TabActivity for a specific Tab

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);
 } 


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()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜