Code example for Fragment

Methods: onCreatesetHasOptionsMenu

0
     */ 
    public static class Menu2Fragment extends Fragment {
 
        @Override 
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setHasOptionsMenu(true);
        } 
 
        @Override 
        public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
            MenuItem item;
            item = menu.add("Menu 2");
            MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
        } 
    } 
} 
Experience pair programming with AI  Get Codota for Java