jQuery Flot charting library in Android WebView doesn't work correctly

I'm trying to implement Flot charts in my Android app using WebView. Basically I have a Fragment which contains a WebView. I also have a refresh button which refreshes the Fragment (and the WebView thus) by retrieving new data from a web service and putting them in the chart.

The problem I'm having is that the WebView at first launch (when the fragment is created) either doesn't show the chart or it shows a smaller chart (i.e. half screen). When I click refresh the chart shows fine without any problem, so the problem is only when the fragment is first created.

What I do on onCreateView is calling this:

chartWebView.loadUrl("file:///android_asset/index.html");

And I have an AsyncTask which retrieves the data from the server, and then calls javascript on the WebView like this:

chartWebView.loadUrl("javascript:displayChart(" + data + ")");

I also have overrided the onResume method where I call the refresh() function.

The refresh() method basically executes the AsyncTask to reload the data, which at onPostExecute(...) calls the javascript on the WebView.

Any hints?

Answers


Just a guess but...

webView.loadUrl() is asynchronous. I think your first AsyncTask executes before the loadUrl completes. I'd recommend to do your initial displayChart in an onPageFinished.


Need Your Help

Split string after certain character count

c# asp.net regex string stringbuilder

I need some help. I'm writing an error log using text file with exception details. With that I want my stack trace details to be written like the below and not in straight line to avoid the user from

Jersey jackson disable filterprovider

java filter jersey jackson dropwizard

Recently I started using SecurityEntityFilteringFeature. Placed below code in jersey environment.