我想通过JSONArray
FromActivity
到HTML Script
我正在尝试以下方式,但我无法获取数据
HTML
活动:-
public class DayViewJSActivity extends Activity {
WebView webviewobj;
String jsurl, eventobj;
JSONArray jArray = new JSONArray();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webviewobj = (WebView) findViewById(R.id.webView1);
webviewobj.getSettings().setJavaScriptEnabled(true);
webviewobj.addJavascriptInterface(new calendarInterface(),
"Androidfunction");
webviewobj.loadUrl("file:///android_asset/caljs.html");
JSONObject jobject = new JSONObject();
try {
jobject.put("id", 1);
jobject.put("start_date", "2012-10-22 09:00:00");
jobject.put("end_date", "2012-10-22 10:00:00");
jobject.put("text", "Demo scheduled");
jobject.put("details:", "");
} catch (JSONException e) {
e.printStackTrace();
}
jArray.put(jobject);
jsurl = "javascript:setData('" + jArray + "')";
System.out.println("JSURL IS :" + jsurl);
webviewobj.loadUrl(jsurl);
}
final class calendarInterface {
calendarInterface() {
}
public void run() {
webviewobj.loadUrl("javascript:setData( " + jArray + ")");
}
}
HTML:-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta name = "viewport" content = "initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no">
<script src="Cjs/dhxscheduler_mobile_rec.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="Cjs/dhxscheduler_mobile_rec.css">
<title></title>
<script type="text/javascript">
var eventData = null;
function setData(eventobj)
{
eventData = eventobj;
}
dhx.ready(function(){
dhx.ui.fullScreen();
dhx.ui(
{
view:"scheduler",
id:"scheduler"
}
);
var data = eventData;
$$("scheduler").$$("buttons").setValue("day");
$$("scheduler").parse(data);
});
</script>
</head>
<body>
</body>
</html>
我应该如何从中获取HTML
值Activity
。