2
votes

onCreateOptionsMenu method is never called even though I have done all the steps from other similar questions (like this one: Menu inside fragment not getting called; and this: onCreateOptionsMenu not being called on FragmentActivity when run on phone version)

1) I call setHasOptionsMenu(true) in onCreate method of the Fragment

2) I override onCreateOptionsMenu(Menu menu, MenuInflater inflater) methd like this

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

[ 3) And also I dp implement onOptionsItemSelected(MenuItem item) ]

WTH?

P.S. I am using android-support-v4.jar.

P.P.S @Philipp Jahoda, I do implement onCreateOptionsMenu(...) in a Fragment's hosting Activity.

1

1 Answers

9
votes

The problem is solved.

I am using ActionBarSherlock, but my fragment class was extending "Fragment" class instead of "SherlockFragment". So onCreateOptionsMenu method was not getting called.

That simple..