/**     * js接口     */    final class JavaScriptInterface {        JavaScriptInterface() {        }        /**         * This is not called on the UI thread. Post a runnable to invoke         * loadUrl on the UI thread.         */        public void showCity() {            mHandler.post(new Runnable() {                public void run() {                        new MyApplication().getCity(getActivity().getApplicationContext());                        String city=MyApplication.city;                 //      String city=getCity();                       mWebView.loadUrl("javascript:js_showCity(" + city + ")");                 //     mWebView.loadUrl("javascript:js_showCity()");                }            });        }    }

一开始,下面这行死活都没反应,把参数传到js里面去,弹出来未定义啊,后来找了很久,原来是忘记写分号了。

mWebView.loadUrl("javascript:js_showCity(" + city + ")");
把这一行改成下面的就可以了

 mWebView.loadUrl("javascript:js_showCity('" + city + "')");


下次一定要注意。

更多相关文章

  1. Android(安卓)ApiDemos示例解析(139):Views->Layouts->Baseline-
  2. android studio mark
  3. The method setOnClickListener(View.OnClickListener)解决办法
  4. android 自定义输入框
  5. android ActionBarImpl can only be used with a compatible win
  6. [Android分享] 如何解决Android(安卓)5.0中出现的警告:Service In
  7. Error inflating class android.support.design.widget.Navigati
  8. Android(安卓)2.2 单点触摸支持的问题
  9. android targetSdkVersion 改成28以后出的问题

随机推荐

  1. 文字效果 - 图像到css / jQuery
  2. JQuery 总结(3) jQuery 各种事件
  3. 【jQuery】判断浏览器类型和版本
  4. Asp。NET MVC Ajax-Post表单和Ajax-Get
  5. Chosen 基于jquery的选择框插件使用方法
  6. 如何在jquery中获取textarea的值?
  7. 如何在Rails 4(使用jquery)中上传多个文
  8. 《JQuery——插件的开发和使用(二)之qTip2
  9. jQuery并在回调中解析JSON
  10. 不仅模糊了Jquery中的一个动作