【发布时间】:2014-12-05 07:40:17
【问题描述】:
我已经使用 MySql 和 PHP 以及 JSON 解析从 Web 服务器获取数据。然后我将数据存储在arraylist中。现在我要做的是创建一个 WebView 并将这些数据插入到 html 字符串中,如下所示:
htmlData = "<html>"+
"<head"+
"<title>Model Question</title>"+
"</head>"+
"<body>"+
"The question of "+"English is :<br />"+getfromServer.get(0).getData()[0]+
"<br /><form>"+
"Option[0]"+"<input type='radio' name='c0' /><br />"+
"Option[1]"+"<input type='radio' name='c1' /><br />"+
"Option[2]"+"<input type='radio' name='c2' /><br />"+
"Option[3]"+"<input type='radio' name='c3' /><br />"+
"</form>"+
"</body>"+
"</html>";
这里的 getfromServer 是 Question_answer 类型的 ArrayList,定义为:
package com.example.mcahelper;
public class Question_answer {
private String Question,Options[] = new String[4];
public void setData(String...datas){
Question = datas[0];
Options[0]=datas[1];
Options[1]=datas[2];
Options[2]=datas[3];
Options[3]=datas[4];
}
public String[] getData(){
String datas[]= new String[5];
datas[0] = Question;
datas[1]=Options[0];
datas[2]=Options[1];
datas[3]=Options[2];
datas[4]=Options[3];
return datas;
}
}
现在我想执行循环以从数组列表中获取 Question_answer 类型的每个对象并将其放入字符串 htmlData 中,该字符串将进一步用作:
webview = (WebView) findViewById(R.id.wbvw);
WebSettings websettings = webview.getSettings();
websettings.setJavaScriptEnabled(true);
webview.loadDataWithBaseURL("http://bar", htmlData,"text/html", "utf-8", "");
我们可以使用 javascript 还是他们的任何其他方式。 请帮忙。 提前致谢!
【问题讨论】:
标签: java javascript php android mysql