[英]Method does not override method from its superclass - Action buttons within a fragment
Method does not override method from its superclass in android when trying to add action buttons from within a fragment.当尝试从片段中添加操作按钮时,方法不会覆盖其在 android 中的超类中的方法。
@Override
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater=getActivity().getMenuInflater();
inflater.inflate(R.menu.forecastfragment, menu);
return true;
}
This is because the onCreateOptionsMenu
function in a fragment requires a second parameter of type MenuInflator
.这是因为片段中的onCreateOptionsMenu
函数需要MenuInflator
类型的第二个参数。
This function is the correct way to do it as per this article .此功能是按照本文执行此操作的正确方法。
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
menuInflater.inflate(R.menu.forecastFragment, menu);
}
Method does not override method from its superclass in android when trying to add action buttons from within a fragment.尝试从片段中添加操作按钮时,方法不会覆盖其在 android 中的超类中的方法。
@Override
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater=getActivity().getMenuInflater();
inflater.inflate(R.menu.forecastfragment, menu);
return true;
}
Don't forget to add setHasOptionsMenu(true);
不要忘记添加setHasOptionsMenu(true);
inside onCreateView
在onCreateView
里面
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.