2
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    web = (WebView) findViewById(R.id.webview1);



    web.setWebChromeClient(new MyWebChromeClient());

    web.addJavascriptInterface(new DemoJavaScriptInterface(), "temp_1");

    web.loadUrl("file:///android_asset/temp_1.html");

  }   
}

final class DemoJavaScriptInterface {

    private Handler mHandler = new Handler();
    WebView web;
    DemoJavaScriptInterface() {
}

public void clickOnAndroid() {
    mHandler.post(new Runnable() {
        public void run() {
            web.loadUrl("javascript:init();");
        }
    });

   }
}

final class MyWebChromeClient extends WebChromeClient {

    private static final String LOG_TAG = "WebViewDemo";
    @Override

    public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
        Log.e(LOG_TAG, message);
        result.confirm();
        return true;
    }
}
4

2 回答 2

1

试着写下这一行

web = (WebView) findViewById(R.id.webview1);
web.setWebChromeClient(new MyWebChromeClient());

web.getSettings().setJavaScriptEnabled(true);

web.addJavascriptInterface(new DemoJavaScriptInterface(), "temp_1");
web.loadUrl("file:///android_asset/temp_1.html");
于 2012-07-31T13:09:46.180 回答
0

[2]:两个元素都来自 html 文件,当要单击“单击它”时,没有任何反应,而是显示我想要的 xml 数据

于 2012-08-01T06:22:31.130 回答