Aiden Strydom
Aiden Strydom

Reputation: 1218

Webview does not load every time

I have a Webview which has to load a static web page from the assets folder. The web page contains a javascript function which works perfectly. The problem is that every so often when the activity starts up the webpage never appears (and often it does. Also the startup activity contains the webview)

On times when the webview does load, and you navigate to another activity and then come back, at time there to the webview does not re-draw

protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);

    actionBar.AddView(mainActionBar);
    formDialog.AddView(LayoutInflater.Inflate(Resource.Layout.googleGraphInWebview, null));

    formDialog.SetMinimumHeight(400);

    graph = FindViewById<WebView>(Resource.Id.graphView);
    list = FindViewById<ListView>(Resource.Id.AppointmentList); // get reference to the ListView in the layout

    appointments.Add(new AppointmentListItem("Appointment: Appointment with Spur Cresta", "Remember to meet with Mike regarding the cost sales!", Resource.Drawable.Icon));
    appointments.Add(new AppointmentListItem("Appointment: Jone's laundry needs to be collected", "Address: 12 Marry Street Roodepoort", Resource.Drawable.Icon));

    list.Adapter = new AppointmentListViewAdapter(this, appointments);
    list.ItemClick += AppointmentListClick;  // to be defined

    LinearLayout sideWidget = FindViewById<LinearLayout>(Resource.Id.SideWidget);
    sideWidget = FindViewById<LinearLayout>(Resource.Id.SideWidget);
    sideWidget.AddView(LayoutInflater.Inflate(Resource.Layout.LineItem, null));

    graph.Settings.JavaScriptEnabled = true;
    graph.SetWebViewClient(new webView(formDialog));
    graph.LoadUrl("file:///android_asset/graph.html");

}

Could you help?

A

Upvotes: 2

Views: 921

Answers (1)

Aiden Strydom
Aiden Strydom

Reputation: 1218

So the real issue was i needed to not only do all the above but specifically add

graph.SetWebChromeClient(new WebChromeClient());
graph.SetWebViewClient(new webView(formDialog));

The SetWebChromeClient(new WebChromeClient()); was very important.

After i added this line the page loaded each time. Instantaneously

A

Upvotes: 2

Related Questions