eternal_developer
eternal_developer

Reputation: 43

Fragment Option Menu in FragmentPagerAdapter

I am using a Custom FragmentPagerAdapter for SwipeViews in ActionBar.NAVIGATION_MODE_TABS mode.

I want the Fragments inside the adapter to provide their custom Menus. But I observed that onCreateOptionsMenu() method inside the Fragment is not getting called even when I used setHasOptionsMenu(true); inside the onCreate() callback of the Fragment.

In short,How can I get custom Options Menu for each Fragment in ViewPager?

Upvotes: 1

Views: 776

Answers (2)

Mohit Sehgal
Mohit Sehgal

Reputation: 865

Actually your problem seems to lie in ViewPager. Either its not instantiated properly or its Visibility is set to Visibility.GONE.
Make sure that ViewPager is Visible on screen by default or there is no code which changes its visibility. Get back to me if problem persists.

Upvotes: 0

Vishal
Vishal

Reputation: 136

Please write the code in onCreateOptionsMenu & onPrepareOptionsMenu of your activity to inflate the from menu xml. You can then customize the menu in your fragment by using these functions inside your fragment again. I tried it and it worked for me.

Upvotes: 1

Related Questions