I am trying to inflate a menu in a class that inherits the Fragment class. Here is my OnCreateOptionsMenu() method -
@Override public boolean OnCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.forecastfragment, menu) ; return true; }
This causes the following error:
Unable to resolve getMenuInflater () 'method
I tried:
MenuInflater inflater = getActivity().getMenuInflater();
but then Android Studio highlights @Override red and states:
The method does not cancel the method from its superclass
I also tried to create the getMenuInflater method in the same class and return it new MenuInflater(this)
public MenuInflater getMenuInflater() { return new MenuInflater(this); }
but then the following error is thrown:
error: incompatible types: ForecastFragment could not be converted to Context
error: the method does not override or does not implement the method from the super type
What should I do?
java android android-fragments android-menu
Flame of udun
source share