0

My Android App has one SherlockFragmentActivity which contains a ViewPager with three SherlockListFragments. Know i want to display different ActionItems in the ActionBar. For example one SettingsItem on all three Fragments and on each Fragment a unique ActionItem for example different sort types. Now i use this code in my Fragment:

@Override
public void onCreateOptionsMenu( Menu menu, MenuInflater inflater )
{
    super.onCreateOptionsMenu( menu, inflater );

    inflater.inflate( R.menu.sort_menu, menu );
}

And this code in my Activity:

@Override
public boolean onCreateOptionsMenu( Menu menu )
{       
    menu.add( Menu.NONE, PREFERENCES_ID, Menu.NONE, getString( R.string.menu_preferences ) )
        .setIcon( R.drawable.ic_menu_settings_dark )
        .setShowAsAction( MenuItem.SHOW_AS_ACTION_ALWAYS );

    return super.onCreateOptionsMenu( menu );
}

The problem is that if i start my app no ActionItems appeare on the first tab. If i slide to another tab and then back again the ActionItems appeare. Sometimes i see only one ActionItem for example the settings item which is created by the parent Activity. Knows anybody a good solution to show some ActionItems on each tab and some unique ActionItems for each tab. I didn't want to copy code to each tab.

EDIT The position of the tab is not important. On the first app start i see no ActionItems on the actual tab.

Happo
  • 1,375
  • 3
  • 16
  • 34
  • This looks like the same issue: http://stackoverflow.com/questions/10544122/actionbarsherlock-with-viewpager-and-actionitems-disappearing?rq=1 – Happo Sep 29 '12 at 15:43
  • I found this post and think it is the best solution or found the root of the issue. http://stackoverflow.com/questions/9338122/action-items-from-viewpager-initial-fragment-not-being-displayed – Happo Oct 05 '12 at 07:22

0 Answers0