Tech tip of this week

Android: Create Menu options in Fragments

To display menu options in fragment, we have to add 'setHasOptionsMenu' method in fragment onCreate().with out this method,menu options will not be visible in fragments.
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setHasOptionsMenu(true);
}

public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  super.onCreateOptionsMenu(menu, inflater);
  inflater.inflate(R.menu.settings_menu, menu);
}

No comments:

Post a Comment