我在我的项目中使用 actionbarsherlock,我正在尝试从片段中操作操作栏......
所以在我显示的第一个片段中,我重写了 onPrepareOptionsMenu 以使操作栏无效并更改标题......但是当我尝试调用 supportInvalidateOptionsMenu() 时,我得到一个 java.lang.StackOverflowError(虽然它不会在 android 4.3 上发生).. .
我已经尝试过Delyan 的解决方案但没有成功......我的代码和日志如下,有什么建议吗?提前致谢
- - - - -代码 - - - - -
@Override
public void onPrepareOptionsMenu(Menu menu){
super.onPrepareOptionsMenu(menu);
Log.e("CategoriasLista", "Executou onPrepareOptionsMenu");
int currentTab = ((MainActivity)getSherlockActivity()).getTabHost().getCurrentTab();
if(currentTab==0){
ActionBar bar = getSherlockActivity().getSupportActionBar();
//getSherlockActivity().supportInvalidateOptionsMenu();
((MainActivity)getSherlockActivity()).runOnUiThread(new Runnable(){
@Override
public void run(){
((MainActivity)getSherlockActivity()).supportInvalidateOptionsMenu();
}
});
bar.setNavigationMode(com.actionbarsherlock.app.ActionBar.NAVIGATION_MODE_STANDARD);
bar.setTitle("Categorias");
}
}
- - - - -日志 - - - - - -
10-21 09:35:32.910: ERROR/AndroidRuntime(5231): FATAL EXCEPTION: main
java.lang.StackOverflowError
at java.lang.Class.getClassLoaderImpl(Class.java:431)
at java.lang.Class.getClassLoader(Class.java:398)
at android.os.Bundle.<init>(Bundle.java:68)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.dispatchInvalidateOptionsMenu(ActionBarSherlockCompat.java:251)
at com.actionbarsherlock.app.SherlockFragmentActivity.invalidateOptionsMenu(SherlockFragmentActivity.java:149)
at com.actionbarsherlock.app.SherlockFragmentActivity.supportInvalidateOptionsMenu(SherlockFragmentActivity.java:155)
at br.com.maisapp.Categorias.CategoriasLista$1.run(CategoriasLista.java:60)
at android.app.Activity.runOnUiThread(Activity.java:3743)
at br.com.maisapp.Categorias.CategoriasLista.onPrepareOptionsMenu(CategoriasLista.java:57)
at android.support.v4.app.Watson.onPreparePanel(Watson.java:98)
at com.actionbarsherlock.ActionBarSherlock.callbackPrepareOptionsMenu(ActionBarSherlock.java:581)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.preparePanel(ActionBarSherlockCompat.java:494)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.dispatchInvalidateOptionsMenu(ActionBarSherlockCompat.java:265)
at com.actionbarsherlock.app.SherlockFragmentActivity.invalidateOptionsMenu(SherlockFragmentActivity.java:149)
at com.actionbarsherlock.app.SherlockFragmentActivity.supportInvalidateOptionsMenu(SherlockFragmentActivity.java:155)
at br.com.maisapp.Categorias.CategoriasLista$1.run(CategoriasLista.java:60)
at android.app.Activity.runOnUiThread(Activity.java:3743)
at br.com.maisapp.Categorias.CategoriasLista.onPrepareOptionsMenu(CategoriasLista.java:57)
at android.support.v4.app.Watson.onPreparePanel(Watson.java:98)
at com.actionbarsherlock.ActionBarSherlock.callbackPrepareOptionsMenu(ActionBarSherlock.java:581)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.preparePanel(ActionBarSherlockCompat.java:494)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.dispatchInvalidateOptionsMenu(ActionBarSherlockCompat.java:265)
at com.actionbarsherlock.app.SherlockFragmentActivity.invalidateOptionsMenu(SherlockFragmentActivity.java:149)
at com.actionbarsherlock.app.SherlockFragmentActivity.supportInvalidateOptionsMenu(SherlockFragmentActivity.java:155)
at br.com.maisapp.Categorias.CategoriasLista$1.run(CategoriasLista.java:60)
at android.app.Activity.runOnUiThread(Activity.java:3743)
at br.com.maisapp.Categorias.CategoriasLista.onPrepareOptionsMenu(CategoriasLista.java:57)
at android.support.v4.app.Watson.onPreparePanel(Watson.java:98)
at com.actionbarsherlock.ActionBarSherlock.callbackPrepareOptionsMenu(ActionBarSherlock.java:581)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.preparePanel(ActionBarSherlockCompat.java:494)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.dispatchInvalidateOptionsMenu(ActionBarSherlockCompat.java:265)
at com.actionbarsherlock.app.SherlockFragmentActivity.invalidateOptionsMenu(SherlockFragmentActivity.java:149)
at com.actionbarsherlock.app.SherlockFragmentActivity.supportInvalidateOptionsMenu(SherlockFragmentActivity.java:155)
at br.com.maisapp.Categorias.CategoriasLista$1.run(CategoriasLista.java:60)
at android.app.Activity.runOnUiThread(Activity.java:3743)
at br.com.maisapp.Categorias.CategoriasLista.onPrepareOptionsMenu(CategoriasLista.java:57)
at android.support.v4.app.Watson.onPreparePanel(Watson.java:98)
at com.actionbarsherlock.ActionBarSherlock.callbackPrepareOptionsMenu(ActionBarSherlock.java:581)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.preparePanel(ActionBarSherlockCompat.java:494)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.dispatchInvalidateOptionsMenu(ActionBarSherlockCompat.java:265)
at com.actionbarsherlock.app.SherlockFragmentActivity.invalidateOptionsMenu(SherlockFragmentActivity.java:149)
at com.actionbarsherlock.app.SherlockFragmentActivity.supportInvalidateOptionsMenu(SherlockFragmentActivity.java:155)
at br.com.maisapp.Categorias.CategoriasLista$1.run(CategoriasLista.java:60)
at android.app.Ac