How to implement the onCreateOptionsMenu method in a SherlockFragment program?

I'm really trying to set up the onCreateOptionsMenu method in my Sherlock fragment, since I usually do not use Sherlock fragments. Can someone say what I need to import and how the implementation works?

Some code that I have:

 public class MyFragment extends SherlockFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.custom_list, container, false); // SOME CODE ... return rootView; } @Override public boolean onCreateOptionsMenu(Menu menu) { // ??? } } 
+7
android actionbarsherlock android-optionsmenu
source share
1 answer

The onCreateOptionsMenu () function from SherlockFragment exactly matches the fragment.

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

Also you need to add the following to your onCreate() function

 setHasOptionsMenu(true); 

Import:

 import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuInflater; 
+22
source share

All Articles