gpt4 book ai didi

android - 如何将 JSONArray 从 Activity 传递到 Html 脚本?

转载 作者:太空宇宙 更新时间:2023-11-03 11:25:34 25 4
gpt4 key购买 nike

我想将 JSONArrayActivity 传递到 HTML Script 我正在尝试以下方式,但我无法获取数据在里面HTML

Activity :-

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>

我应该如何从 Activity 获取 HTML 中的值。

最佳答案

在 HTML 文件的每一个地方明确地写下你的文件的位置

file:///android_asset/Cjs/dhxscheduler_mobile_rec.js

关于android - 如何将 JSONArray 从 Activity 传递到 Html 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13011275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com