java - Passing an array of values from Android Activity to JavaScript in a WebView -


i'm using js charts library draw graphs in webview of android application. want provide data sqlite database. @ moment i'm stuck on how pass array of data java javascript. javascript part expects that:

data = new array([10, 10], [20, 10]); 

i know addjavascriptinterface , managed pass single values activity webview. it's array gives me trouble. thought that:

final class chartdataloader {      public double[][] getdata() {         double[][] data = {{10, 10}, {20, 10}};         return data;     } } 

note i'm hard-coding data, pulled out database. expose js:

webview.addjavascriptinterface(new chartdataloader(), "dataloader"); 

and try read in javascript:

<html> <head> <script type="text/javascript" src="jscharts.js"></script> </head>  <body> <div id="chartcontainer">you should see chart here.</div>  <script type="text/javascript">   mydata = dataloader.getdata();   alert("datareceived: " + mydata.length);  alert("element 0 : " + mydata[0]);   var mychart = new jschart('chartcontainer', 'line');  mychart.setdataarray(mydata);  mychart.draw();  </script> </body> </html> 

javascript fails on 2 alert statements stating:

error/web console(2455): uncaught typeerror: cannot read property 'length' of undefined @ file:///android_asset/chart.html:15

any hints? saw code online other people convert arrays string , recreate in javascript seems overkill me , hoping better solution. alternative pass xml file chart library, again, thought slow create new xml every time user wants see graph.

remove line: alert("datareceived: " + mydata.length);


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -