I have a webview with HTML webpage which is downloaded from server and i populate dynamic data and add rows of information to this webpage. I have used the following code on that webpage to enable javascript:
class JSClass {
Context jsContext;
JSClass(Context c){
jsContext = c;
}
public void getHTMLContent(String info)
{
Log.i(TAG, "Info: "+info);
}
}
WebView webview = (WebView) findViewById(R.id.webView);
webview.loadDataWithBaseURL("", htmlcontent, "text/html", "utf-8", "");
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebChromeClient(new WebChromeClient());
webview.addJavascriptInterface(new JSClass(this), "Android");
webview.loadUrl("javascript:"+
"var rows = document.getElementsByClassName('info');"+
"if(rows !== null){"+
"for(var i=0;i<rows.length;i++){"+
"rows[i].onclick = function(){"+
"var workId = 0;"+
"workId = parseInt(this.cells[0].innerHTML);"+
"window.Android.getHTMLContent(workId);"+
"}}}"
);
when i click on any row, i cal an intent to download images from the server depending on the row data. It works fine on first click, but the second time i click, the application closes without any error. I don't understand the reason. Please help. Thanks in advance
LogCatyou don't have a clue?ChartWebChromeClient#onConsoleMessagemessage and print out each message to LogCat. Note that the API was introduced in FROYO so be sure to defend against that if you are running sub v2.2