Code example for Fragment

Methods: onCreate, setHasOptionsMenu

0
    } 
     
    public final class TestFragment extends Fragment {
		@Override 
		public void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
    		setHasOptionsMenu(true);
		} 
 
		@Override 
		public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
			menu.add(0, 0, 0, MENU_ITEM_TEXT)
				.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
		} 
		 
		@Override 
		public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
			return new FrameLayout(getActivity());
		} 
 
		@Override