In the Fragment
where you don't want to show any menu options, you need setHasOptionsMenu(false);
in the onCreate()
, like this:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(false);
}
However, the menu that is being shown that you would like to hide (REFRESH), belongs to MainActivity. That is why it is always shown. Since you want to control the menu at the Fragment
level (and not show an Activity
options menu), my suggestion is to delete the menu code from the Activity
and implement it in your Fragment
.
Activity
s and Fragment
s can each have their own separate menus. See this link.