WebView 为空,直到我触摸该组件 [英] WebView empty until I touch the component
本文介绍了WebView 为空,直到我触摸该组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在向 Volley 图书馆提出请求.来自网络的响应存储在一个字符串中.因此,我通过以下方式加载带有这些数据的 webview:
I'm doing a request with Volley Library. The response from the network is stored in a String. So, I load a webview with this data by the next way:
webView.loadData(response, "text/html; charset=UTF-8", null);
我的问题是网页已加载,但仅在我触摸网页视图时才显示.我可以做什么来更新视图?
My problem is that the web is loaded, but It is only showed when I touch the webview. What I can do to update the view?
源代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_register_oauth, container, false);
//Queue of petitions
volley_queue = Volley.newRequestQueue(container.getContext());
webView = (WebView) view.findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
//MANDAR PETICION
StringRequest postReq = new StringRequest(Request.Method.POST, pathto.get_register_service(), new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("VolleyReq", "onResponse\n " + response);
webView.loadData(response, "text/html; charset=UTF-8", null);
webView.reload();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.i("VolleyReq", "onResponse\n " + error);
}
});
volley_queue.add(postReq);
return view;
}
谢谢.
推荐答案
这段代码对我有用:
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
webView.loadData(received_response, "text/html; charset=UTF-8", null);
}
});
这篇关于WebView 为空,直到我触摸该组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文