Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionBar Menu Items disappear in NestedFragments

Since android 4.2 now support NestedFragment , and added it to support v13.

I use this NestedFragment on a classic situation : Create fragmentA that can swipe left and right and consume a majority of the screen space, and insert fragmentB and fragmentC into each fragment page.

My Problem is the MenuItem I create in fragmentB and fragmentC can`t show on Activity`s actionbar.Which before I use NestedFragment , it works well.

like image 237
Wangchao0721 Avatar asked Jan 03 '13 10:01

Wangchao0721


1 Answers

got at some point the same problem. If you're using the ActionBarSherlock library this is a small bug. What you basically have to do is to call from your parent fragment from the onCreateOptionsMenu() method the onCreateOptionsMenu() method of the children, something like:

public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    getChildFragment().onCreateOptionsMenu(menu, inflater);
}

hope this works, let me know.

Cheers.

like image 85
Radu Comaneci Avatar answered Sep 22 '22 07:09

Radu Comaneci