Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why is my onPrepareOptionsMenu not getting called?

Tags:

java

android

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 my onPrepareOptionsMenu inside my Fragment class, buts its not getting called. I want to refresh my menu item when i click on an action tab inside my action bar.

like image 220
theJava Avatar asked Mar 19 '13 14:03

theJava


1 Answers

Call setHasOptionsMenu(true) in onAttach method

like image 54
Dmitry Zaytsev Avatar answered Nov 20 '22 16:11

Dmitry Zaytsev