2 Question: How To Use Progress Bar

question created at Sat, Jun 1, 2019 12:00 AM

I am making app with Android Studio, and i have added pull down to refresh url in app and after than my Progress Bar is not working , i mean when i pull down default progress bar shows but after that screen show only blank page until url loaded. this is my xml file

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <WebView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/webview"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_above="@+id/adView" />



</ScrollView>


<ProgressBar
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_gravity="center"
    android:id="@+id/progressBar"/>

and in java file i use this

 myWebView.loadUrl("http://m.wahstatus.com/ws/english-status/?orderby=rand");
                WebSettings webSettings = myWebView.getSettings();
                myWebView.getSettings().setLoadWithOverviewMode(true);
                webSettings.setJavaScriptEnabled(true);
                swipeView.setColorScheme(android.R.color.holo_blue_dark,android.R.color.holo_blue_light, android.R.color.holo_green_light,android.R.color.holo_green_dark);
                swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener()
                {
                    @Override
                    public void onRefresh()
                    {
                        swipeView.setRefreshing(true);
                        ( new Handler()).postDelayed(new Runnable()
                        {
                            @Override
                            public void run()
                            {
                                swipeView.setRefreshing(false);
                                myWebView.loadUrl("http://m.wahstatus.com/ws/english-status/?orderby=rand");
                            }
                        }, 1000);
                    }

                });


                myWebView.setWebViewClient(new WebViewClient() {
                    public void onPageStarted(WebView view, String url, Bitmap favicon) {
                        super.onPageStarted(view, url, favicon);
                        findViewById(R.id.progressBar).setVisibility(View.VISIBLE);
                    }
                    @Override
                    public void onPageFinished(WebView view, String url) {
                        findViewById(R.id.progressBar).setVisibility(View.GONE);
                    }

On page loaded Progress bar not working

-1
  1. What is the root for your layout ? add whole layout with question .
    2019-06-01 04:41:48Z
2 Answers 2

It is because you are assuming web page will be loaded in one second,

Suggest, read async & sync

Solution: you have callbacks for page finished and page started. use them based on your needs.

Secondly, It seems your root layout is SwipeRefreshLayout. it will come with its default progress bar, why are adding a new one?

0
2019-06-01 04:59:21Z

you should add a webchromeClient()

 webview.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress)   
            {
               findViewById(R.id.progressBar).setProgress(progress * 100); //Make the bar disappear after URL is loaded
            });
0
2019-06-01 05:09:18Z
source placed here