所以我一直在开发一个顶部有一个导航栏和几个选项卡的 Android 应用程序,这部分工作正常,但现在我希望能够从不同的片段动态地将菜单项添加到操作栏(因为一些片段可能有不同的可用选项)。到目前为止,无论我尝试了什么,我似乎都无法调用 onCreateOptionsMenu。这是我到目前为止所拥有的
//First I have a holder class that is used to navigate between the different Fragment Tabs
 public class ActionHolder extends SherlockFragmentActivity implements ActionBar.TabListener {....
//And then I have this method for switching Fragments based on what Tab is selected
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
    // TODO Auto-generated method stub
    int selectedTab = tab.getPosition();
    if (selectedTab == 0) {
        SalesMainScreen salesScreen = new SalesMainScreen();
        ft.replace(R.id.content, salesScreen);
    }
    else if (selectedTab == 1) {
        ClientMainScreen clientScreen = new ClientMainScreen();
        ft.replace(R.id.content, clientScreen);
    }.....
现在这是选项卡的片段之一(SalesMainScreen),我希望将一些菜单项添加到操作栏中
 @Override
public void onCreate (Bundle savedInstanceState) {
    Log.i("message","the oncreate method was called");
    setHasOptionsMenu(true);
    super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle saved) {
    return inflater.inflate(R.layout.salesmainscreen, group, false);
}
@Override
 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    Log.i("message", "the oncreatemenu method called");
    inflater.inflate(R.menu.menu_refresh, menu);
    super.onCreateOptionsMenu(menu, inflater);
}
我看到 OnCreate Log 消息被调用,但我根本没有看到 onCreateOptionsMenu Log 被调用。另外,我知道有时导入会导致问题,但是当我导入 Sherlock Menu 和 Menu Inflater 时,我会在 OnCreateOptionMenu 方法上收到关于它们不兼容的各种错误消息。在此设置中是否可以将菜单项动态添加到操作栏,或者我应该只添加项目然后不对那些不适用于正在显示的片段的项目执行任何操作?