Why is my onPrepareOptionsMenu not getting a call?

public class BFragmentTab extends Fragment {

    @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            // Inflate the layout for this fragment
            return inflater.inflate(R.layout.recents, container, false);
     }

    @Override
    public void onPrepareOptionsMenu(Menu menu) {
        menu.clear();
        MenuItem filter = menu.findItem(R.id.filter);
        MenuItem refresh = menu.findItem(R.id.refresh);
        //depending on you conditions, either enable/disable
        filter.setEnabled(false);
        refresh.setEnabled(false);
        super.onPrepareOptionsMenu(menu);
    }
}

I am trying to call mine onPrepareOptionsMenuinside my Fragment class, but it does not receive it. I want to update my menu item when I click action tabinside mine action bar.

+5
source share
2 answers

Call setHasOptionsMenu(true)to onAttachmethod

+13
source

I got the same error, and in my case there was an error in my xml layout file for one of the sub-actions.

Surprisingly, Eclipse did not find the error, but after its removal the program worked.

0
source

All Articles