In my fragment I have the following, however my menu never gets inflated. I have a Toolbar in my layout of the fragment.
In my Logcat I get the following output (filtering on TAG which is "Fragment1"). There is no "Woohoo" output, showing that onCreateOptionsMenu never gets called.
Could someone assist me please? I use a ViewPager on my MainActivity to hold all the fragments in.
08-28 11:20:56.822 9118-9118/? I/Fragment1: 1
08-28 11:20:56.823 9118-9118/? I/Fragment1: 2
08-28 11:20:56.845 9118-9118/? I/Fragment1: 3
In my Logcat I get the following output (filtering on TAG which is "Fragment1"). There is no "Woohoo" output, showing that onCreateOptionsMenu never gets called.
Could someone assist me please? I use a ViewPager on my MainActivity to hold all the fragments in.
08-28 11:20:56.822 9118-9118/? I/Fragment1: 1
08-28 11:20:56.823 9118-9118/? I/Fragment1: 2
08-28 11:20:56.845 9118-9118/? I/Fragment1: 3
Code:
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
Log.i(TAG, "1");
setHasOptionsMenu(true);
Log.i(TAG, "2");
View view = inflater.inflate(R.layout.fragment_main_layout, container, false);
btnNavFragInnovations = (Button) view.findViewById(R.id.button1);
btnNavFragTraining = (Button) view.findViewById(R.id.button2);
btnNavFragForms = (Button) view.findViewById(R.id.button3);
Log.i(TAG, "3");
btnNavFragInnovations.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((MainActivity)getActivity()).setmViewPager(1);
}
});
btnNavFragTraining.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((MainActivity)getActivity()).setmViewPager(2);
}
});
btnNavFragForms.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((MainActivity)getActivity()).setmViewPager(3);
}
});
return view;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
Log.i(TAG, "woohoo");
menuInflater.inflate(R.menu.top_menu, menu);
super.onCreateOptionsMenu(menu, menuInflater);
}