I am trying to display some formatted html text in a fragment. I have seen the other similar resolved issues but they mostly involve getting the html and css into the project local assets.
For what I am trying to do, the html and css are in exteal locations and can't be downloaded/copied locally (see below). However, when the app runs, the css formatting wasn't applied to the text. Can anyone help me please ..?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_terms, container, false);
final ImageButton menuButton = (ImageButton) view.findViewById(R.id.title_left_btn);
menuButton.setOnClickListener(this);
final WebView webView = (WebView) view.findViewById(R.id.terms_webview);
JSONObject params = new JSONObject();
try {
//loading html text here
params.put("Object_Name", "abc-terms-conditions");
} catch (JSONException e) {
e.printStackTrace();
}
QuikFixJSONObjectRequest req = new QuikFixJSONObjectRequest(Request.Method.POST,
NetworkHelper.getFeedbackURL
() + "GetContent", params,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
Log.i(TAG, response.toString(3));
String content = response.getString("content");
String decodedContent = Html.fromHtml(content).toString();
String cssFile = response.getString("style_file");
//formatting the html with exteal css styles link
String formattedContent = "<html><head><link rel="stylesheet" " +
"href="http://api-stag.abc.co/v1/pub-files/content-css/"
+ cssFile + ""></head><body><p>" + decodedContent +
"<p/></body></html>";
webView.loadData(formattedContent, "text/html", null);
} catch (JSONException e) {
e.printStackTrace();
}
getProgressHUD().dismiss();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.e("Error: ", error.getMessage());
getProgressHUD().dismiss();
}
});
req.setTag(TAG);
getProgressHUD().show();
NetworkHelper.getInstance(getActivity()).addToRequestQueue(req);
retu view;
}
