1

I Have a Fragment inside an Activity. This Activity contains OptionsMenu.

I use a FragmentTransaction to launch a new instance of the same Fragment class, when I selected the OptionsMenu, it appears in double because it load twice.

How can I do to manage OptionsMenu between the Fragments

Thanks.

PS : Sorry for the English

tgirard12
  • 11
  • 3
  • I find a part of the solution. I use FragmentTransaction and not an new Intent. But my new question is how to manage the OptionMenu inside the Fragments. – tgirard12 Aug 24 '11 at 15:44

3 Answers3

0

There is no way such way. You can handle on BackPressed and show your own custom menu as a new fragmnet. Or manage your options menu inside of FragmentTransaction inactivity in dependent of your fragment class and content

RChugunov
  • 794
  • 2
  • 11
  • 26
0

I find a solution,

I create the OptionsMenu only in the Activity. I get the OptionsItemsSelected on the Activity too.

When onOptionsItemSelected() occur, I get the current Fragment like this :

FragmentManager fg = getSupportFragmentManager();
Fragment frag = fg.findFragmentById(R.id.fragmentMap);

All my Fragment have the same id but I always get the Fragment on the top. Then, I can call :

frag.onOptionsItemSelected(item);

to the Fragment receive and my UI is correctly update.

I hope It helps.

tgirard12
  • 11
  • 3
0

Try playing with setHasOptionsMenu(boolean) in your Fragment extending classes, if that is set to true the FragmentManager should automatically call your current fragment's onOptionsItemSelected, it set to false you can manually call those callbacks yourself in your Activity's onOptionsItemSelected.

Worked for me... :)

marmor
  • 27,641
  • 11
  • 107
  • 150