Reputation: 61
I am new to css and android. I am trying to load a gist in a webview but the code's indentation is not coming when i am using webview.loadData(content, "text/html", "utf-8");
It is working well when i use webview.loadUrl(url);
but I want the previous. Am I missing something big here? Oh and the indentation is coming in gist by css property white-space: pre;
. Here is my code:
final WebView webview = (WebView)getActivity().findViewById(R.id.algoView);
webview.getSettings().setJavaScriptEnabled(true);
//webview.loadUrl("https://gist.github.com/tanaykumarbera/c9f7f3e7490a1c002649/" ); // works perfectly
AsyncHttpClient client = new AsyncHttpClient();
client.get("https://gist.github.com/tanaykumarbera/c9f7f3e7490a1c002649", new AsyncHttpResponseHandler() {
@Override
public void onStart() {
}
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] res) {
String data="";
ByteArrayInputStream b = new ByteArrayInputStream(res);
String response = "";int c;
while( (c = b.read()) != -1) {
response += Character.toString((char) c);
}
webview.loadData(response, "text/html", "utf-8"); // Not Working!!
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
}
@Override
public void onRetry(int retryNo) {
}
});
}
Screenshots:
http://postimg.org/image/rjz6e18fv/
http://postimg.org/image/u2kvepu63/
Any ideas on how to load it locally or should I read raw markdown instead would be appreciated thanks!
Upvotes: 0
Views: 664
Reputation: 61
After fiddling with it for quite a while I found that instead of
webview.loadData(response, "text/html", "utf-8");
using
webview.loadDataWithBaseURL("", response, "text/html", "utf-8", null);
fixes the issue although I have no idea why the css tabs are not working with the previous code.
Upvotes: 5