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");
        } 
	     
	} 
} 
Connect your IDE to all the code out there  Get Codota for Java