• 4
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I'm a newbie to android am I'm developing an app wich contains fragments. One of the fragments contains a WebView. I'm using a ProgressBar as it is mentioned in many tutorials for webviews so that there is a loading animation when the page loads. The problem is, when I run the app and load a page in WebView (no matter if external device or emulator) the progress bar appears with a small delay (approx. 2 seconds) and not directly after pressing a link for example. Only shortly before the new page starts to load, it appears briefly and disappears again as desired when the page is loaded.

I've tested several android versions and It works fine on all of them except for Android 9.0

Here is my WebViewClient class that I'm using for my webView:

private class MyWebviewClient extends WebViewClient {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            webProgress.setVisibility(View.VISIBLE);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            webProgress.setVisibility(View.GONE);
        }

    }

And here is my xml layout file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyle"
        android:layout_centerInParent="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />


</RelativeLayout>

I just can't figure out what I'm doing wrong.

      • 1
    • Your progress bar is set to visible when the page load starts. My guess is that page load doesn't start immediately. Try setting the progress bar visible in the onCreate method of your Activity or Fragment.
    • i think webview is hided the progress bar.Better to update the width and height of the webview as wrap_content.Then check it
      • 1
    • I tried all your suggestions but unfortunately none worked. I think I forgot to mention that the ProgressBar works as desired when you first open the WebView. Only when you click on a link in the loaded WebView the problem appears.

I found the answer myself. I had to overwrite shouldOverrideUrlLoading() instead of onPageStarted() so that the ProgressBar is displayed immediately after clicking a link and not later.

private class MyWebviewClient extends WebViewClient {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            webProgress.setVisibility(View.VISIBLE);
            return super.shouldOverrideUrlLoading(view, url);
    }

        @Override
        public void onPageFinished(WebView view, String url) {
            webProgress.setVisibility(View.GONE);
        }

}
  • 1
Reply Report

I found a behavior changed between old version Webview and newer version Webview.

enter image description here

old version Webview call onPageStart when first step, but newer version (i test on 74) call onPageStart when "Waiting" step.

So change code to OnProgressChanged to reslove this problem.

  • 0
Reply Report
      • 1
    • Thanks for the research but then I would have to use the WebChromeClient, otherwise I cannot overwrite onProgressChanged.