Code example for MenuItem

Methods: getTitle

0
            super.onCreateOptionsMenu(menu, inflater);
        } 
 
        @Override 
        public boolean onOptionsItemSelected(MenuItem item) {
            if (item.getTitle().equals("Menu 1a")) {
                Toast.makeText(getActivity(), "Selected Menu 1a.", Toast.LENGTH_SHORT).show();
                return true; 
            } 
            if (item.getTitle().equals("Menu 1b")) {
                Toast.makeText(getActivity(), "Selected Menu 1b.", Toast.LENGTH_SHORT).show();
                return true; 
            } 
            return super.onOptionsItemSelected(item);
        } 
    } 
 
    /** 
     * Second fragment with a menu. 
     */ 
    public static class Menu2Fragment extends Fragment {