福尔摩斯动作条invalidateOptionsMenu() [英] Sherlock Actionbar invalidateOptionsMenu()

查看:181
本文介绍了福尔摩斯动作条invalidateOptionsMenu()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里一个很大的错误。 我试图改变动作条的菜单与supportInvalidateOptionsMenu();但在执行功能时,应用程序关闭,没有错误。

I'm with a big error here. I'm trying to change the actionbar menus with the supportInvalidateOptionsMenu(); but when the function is executed, the application closes, without errors.

但奇怪的是,一切都正常工作,在我的Galaxy Nexus的(4.2.2),但在我朋友的手机(安卓4​​.0.3),也没有在我的仿真器与Android 2.1不能正常工作

The strange thing is that everything works normally on my Galaxy Nexus (4.2.2), but does not work in my friend's mobile (android 4.0.3) nor in my emulator with android 2.1

下面是我的code:

protected void onCreate(Bundle savedInstanceState) {
...
actionbar = getSupportActionBar();
...
myWebView = (WebView) findViewById(R.id.webview);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.addJavascriptInterface(new WebAppInterface(this), "Android");
myWebView.loadUrl(getString(R.string.site_load));
...
}

public class WebAppInterface {
SherlockActivity mActivity;
WebAppInterface(SherlockActivity c) {mActivity = c;}  
public void setrefreshon() {showRefresh = true; mActivity.supportInvalidateOptionsMenu();}
}

有人能帮助我吗? :/

Can someone help me? :/

推荐答案

这是最有可能的一个线程问题。现在你可以看到主线程之外约UI访问记录的错误。也许你筛选出来?看完整的日志,而不仅仅是记录你的包。

This is most likely a threading issue. You should be seeing logged errors about UI access outside of main thread. Perhaps you're filtering them out? Look at the full log, not just the log for your package.

构建Web应用程序在web视图的:

注:绑定到你的JavaScript对象运行在另一个   螺纹而不是在它被构造的螺纹

Note: The object that is bound to your JavaScript runs in another thread and not in the thread in which it was constructed.

尝试:

mActivity.runOnUiThread(new Runnable(){
  @Override
  public void run(){
    mActivity.supportInvalidateOptionsMenu();
  }
});

这篇关于福尔摩斯动作条invalidateOptionsMenu()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆