Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove back stack fragment's menu items?

I have a fragment that I'm replacing with another, while also adding the transaction to the back stack. Both of my fragments provide menu items to the action bar using ActionBarSherlock. However, I'm having a problem -- in my second fragment, the action bar shows both the first fragment's and the second fragment's items; I only want the second one's items. Is there any way to achieve this?

(I'm also using the support library.)

like image 781
jmgrosen Avatar asked Jun 02 '12 20:06

jmgrosen


1 Answers

If you want to update the action bar icons, you can override onCreateOptionsMenu() in the activity to define which menu is used for the active fragment. Then call invalidateOptionsMenu() after replacing fragments to recreate the menu.

If you're only using the drop down menu, you can override onPrepareOptionsMenu() and add/remove items from the menu.

like image 138
Jereld Avatar answered Oct 06 '22 12:10

Jereld