在我的代码中调用supportInvalidateOptionsMenu()时出现错误:
无法对ActionBarActivity类型的非静态方法supportInvalidateOptionsMenu()进行静态引用
这是我的代码(必须是静态的):
public static void reCreateSpinner(){
supportInvalidateOptionsMenu();
SpinnerMenuForm.clear();
Variabel.total_unconfirmed=String.valueOf((Integer.parseInt(Variabel.hsd_unconfirmed) )+(Integer.parseInt(Variabel.mfo_unconfirmed))+(Integer.parseInt(Variabel.fuel_unconfirmed)));
SpinnerMenuForm.add(new SpinnerNavItem(Variabel.total_unconfirmed,Variabel.hsd_unconfirmed , "Fill Order - HSD Bunker","HSD"));
SpinnerMenuForm.add(new SpinnerNavItem(Variabel.total_unconfirmed,Variabel.mfo_unconfirmed , "Fill Order - MFO Bunker", "MFO"));
SpinnerMenuForm.add(new SpinnerNavItem(Variabel.total_unconfirmed,Variabel.fuel_unconfirmed , "Fill Order - FUEL Bunker", "FUEL"));
}
那么正确的代码怎么样?谢谢..对不起我的英文
答案 0 :(得分:0)
如果您可以传入FragmentActivity,则此方法正在尝试操作:
public static void reCreateSpinner(FragmentActivity activity){
activity.supportInvalidateOptionsMenu();
SpinnerMenuForm.clear();
Variabel.total_unconfirmed=String.valueOf((Integer.parseInt(Variabel.hsd_unconfirmed) )+(Integer.parseInt(Variabel.mfo_unconfirmed))+(Integer.parseInt(Variabel.fuel_unconfirmed)));
SpinnerMenuForm.add(new SpinnerNavItem(Variabel.total_unconfirmed,Variabel.hsd_unconfirmed , "Fill Order - HSD Bunker","HSD"));
SpinnerMenuForm.add(new SpinnerNavItem(Variabel.total_unconfirmed,Variabel.mfo_unconfirmed , "Fill Order - MFO Bunker", "MFO"));
SpinnerMenuForm.add(new SpinnerNavItem(Variabel.total_unconfirmed,Variabel.fuel_unconfirmed , "Fill Order - FUEL Bunker", "FUEL"));
}
supportInvalidateOptionsMenu()
可在FragmentActivity
及其子类(例如ActionBarActivity