0

I have a fragment that is called before then activity's onCreateOptionsMenu(Menu menu) method.

First is called fragment's onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) method.
When this method is finished is called the other one activity's method.

The problem is that i need to work inside onCreateView() fragment method with the menu, so i'm finding a way to call first the menu activity's method.

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_media_annuale, container, false);  

        final StudentGrades activity = ((StudentGrades)getActivity());
        //here the activity onCreateOptionsMenu(Menu menu) 
        //method have to be called

        //here i begin to check something with the menu 
        //(for this reason i need that it's ready)
        //
        //...
        //
        return rootView;

}

i'm reading some solutions for example calling: activity.invalidateOptionsMenu(); method. But it doesnt work.

Giovanni Far
  • 1,623
  • 6
  • 23
  • 37
  • What are you trying to do, exactly? Any changes a Fragment needs to make to the menu is usually done in the Fragment's `onCreateOptionsMenu()` method. – Mike M. Dec 15 '14 at 01:41
  • I tried to ovveride the onCreateOptionsMenu() of the fragment but still first is called the onCreateOptionsMenu() of the activity, i need to have the menu ready inside the onCreateView() because in this method i have to check something with the menu – Giovanni Far Dec 15 '14 at 01:45
  • Could that something be, instead, passed as an argument to the Fragment? – Mike M. Dec 15 '14 at 01:55
  • i don't understand what do you mean, can you give me an example? – Giovanni Far Dec 15 '14 at 02:25
  • Have a look at this post: http://stackoverflow.com/questions/17436298/how-to-pass-a-variable-from-activity-to-fragment-and-pass-it-back – Mike M. Dec 15 '14 at 02:27

0 Answers0