Code example for Fragment

Methods: getActivity

0
            setHasOptionsMenu(true);
        } 
 
        @Override 
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            return new TextView(getActivity());
        } 
 
        @Override 
        public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
            menu.add("Test");
        } 
	     
	} 
} 
Contextual code suggestions in your IDE  Get Codota for Java