Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] java – Loading created by ProgressDialog wouldn’t stop , how to hide progressbar when page is loaded

Posted on November 14, 2022

Solution 1 :

You have declared setWebViewClient twice , ie after load url you again
declared the setWebViewClient with your custom client , correct answer is

    public class MainActivity extends AppCompatActivity {
    private WebView mywebView;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final ProgressDialog pd = ProgressDialog.show(this, "", "Loading...",true);
        mywebView = (WebView) findViewById(R.id.webview);
        mywebView.getSettings().setJavaScriptEnabled(true);
        mywebView.getSettings().setSupportZoom(true);
        mywebView.getSettings().setBuiltInZoomControls(true);
    webView.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
        pd.show();
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        if(pd!=null && pd.isShowing())
            {
                pd.dismiss();
            }
    }

    @Override
    public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
        super.onReceivedError(view, request, error);
         if(pd!=null && pd.isShowing())
            {
                pd.dismiss();
            }
    }
});
        mywebView.loadUrl("https://google.com");
        
    }
   
    
    @Override
    public void onBackPressed() {
        if(mywebView.canGoBack())
        {
            mywebView.goBack();
        }
        else
        {
            super.onBackPressed();
        }
    }
    
    }

Solution 2 :

Place a breakpoint in

onPageFinished

and see if the listener actually get called?

Problem :

I’m new to Java and was trying to create a web-view app. The loading widget was created using Progress Dialog but it wouldn’t stop. I don’t know what is wrong. Please help.

public class MainActivity extends AppCompatActivity {
private WebView mywebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final ProgressDialog pd = ProgressDialog.show(this, "", "Loading...",true);
    mywebView = (WebView) findViewById(R.id.webview);
    mywebView.getSettings().setJavaScriptEnabled(true);
    mywebView.getSettings().setSupportZoom(true);
    mywebView.getSettings().setBuiltInZoomControls(true);
    mywebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            if(pd!=null && pd.isShowing())
            {
                pd.dismiss();
            }
        }
    });
    mywebView.loadUrl("https://google.com");
    mywebView.setWebViewClient(new WvClient());
}
private class WvClient extends WebViewClient
{
    @Override
    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError er) {
        handler.proceed();
    }
}

@Override
public void onBackPressed() {
    if(mywebView.canGoBack())
    {
        mywebView.goBack();
    }
    else
    {
        super.onBackPressed();
    }
}

}

Comments

Comment posted by Manoj Raj

Thank you for your reply. I tried this but the pd in following code is turning red. I don’t know what that means. @Override public void onPageFinished(WebView view, String url) { if(pd!=null && pd.isShowing()) { pd.dismiss(); } }

Comment posted by Manoj Raj

Now it says that it cannot find the symbol getActivity() in Toast.makeText(getActivity(), “Cannot load page”, Toast.LENGTH_SHORT).show();

READ  [ANSWERED] android - import multiable users from csv or excel to firbase auth
Powered by Inline Related Posts

Comment posted by Quick learner

remove this line Toast.makeText(getActivity(), “Cannot load page”, Toast.LENGTH_SHORT).show(); , updated my answer

Comment posted by Manoj Raj

I changed it to getApplication() and its working. Hope it doesn’t break anything else ;). Thank you soo much.

Comment posted by Quick learner

i am glad it worked , please upvote and check the tick icon also

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress