美好的一天!
我有一个WebView,你得到一个json,我打算将webview作为接收数据挂载,这部分代码" html + =" " + nmTitle +" &#34 ;;" 我把接收json内容的变量放在这个部分" nmTitle = object.optString(" nmTitle")",它高于接收json的处理程序中的代码。 但是,我的WebView不是接收分配的内容,而是将标题显示为" null",看来,他携带WebView以便以后接收json,如何更改它为他分配内容然后发送到html?
public class InfoFragment extends Activity {
private AbstractNetworkHandler handler;
String nmTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_activities_list2);
final WebView wv = new WebView(this);
final LinearLayout ll = (LinearLayout) findViewById(R.id.LinearLayout1);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
wv.setLayoutParams(lp);
//this.handler = AbstractNetworkFactory.build(this, NetworkAction.WEB_VIEW);
this.handler = AbstractNetworkFactory.build(super.getBaseContext(), NetworkAction.WEB_VIEW);
Log.i("webview", "ate aki foi");
handler.get(23L, new HttpJsonObjectListener() {
@Override
public void onRequestCompleted(final JSONObject object, Integer httpStatus, CharSequence msg) {
// final JSONArray array = object.optJSONArray("searchResultsCollection");
nmTitle = object.optString("nmTitle");
final JSONArray array = object.optJSONArray("searchResultsCollection");
String s = String.valueOf(nmTitle);
// json.setText("My Awesome Text");
Log.i("webview", s);
Log.i("webview", "recebendo json");
}
}, new HttpFailListener() {
@Override
public void onRequestCompleted(Exception e, Integer httpStatus, CharSequence msg) {
Log.i("webview", "falhou ao obter json");
}
});
// (WebView) findViewById(R.id.webView1);
WebSettings ws = wv.getSettings();
ws.setJavaScriptEnabled(true);
ws.setSupportZoom(false);
// wv.loadUrl("http://www.thiengo.com.br/img/system/logo/thiengo-80-80.png");
String html = "<html>";
html += "<body>";
html += "<h1>" + nmTitle + "</h1>";
html += "<img src=\"http://www.exemplo.com.br/img/system/logo/-80-80.png\" style=\"float: left; display: block; margin-right: 10px;\" />";
for(int i = 0; i < 3; i++) {
html += "<h3 id=\"h3\" style=\"float: left;\">Texto auxiliar " + (i + 1) + "</h3>";
}
html += "<script type=\"text/javascript\">";
html += "document.getElementById('h3').style.color = '#ff0000';";
html += "</script></body></html>";
wv.loadData(html, "text/html", "UTF-8");
ll.addView(wv);
}
}