Maroof Mandal
Maroof Mandal

Reputation: 531

How to Stop Android webView swipeToRefresh loading progressbar?

Note: This question was already asked here. which did not get any answer so I decided to repost it with my code.

I want a webView to refresh the current page when a user pulls down the screen from the top which is working fine. The problem is the loading progress bar isn't stopping after the page has been loaded.

Here's the MainActivity.java

// Swipe to Refresh
        SwipeRefreshLayout swipeLayout = (SwipeRefreshLayout)this.findViewById(R.id.swipeToRefresh);
        swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                myWebView.reload(); // refreshes the WebView
            }
        });
    }
@Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            progressBar.setVisibility(View.GONE);
            if (null != swipeLayout && swipeLayout.isRefreshing()) {
                swipeLayout.setRefreshing(false);
            }
        }

I have updated the code but it's still loading.

Upvotes: 3

Views: 2833

Answers (3)

Maroof Mandal
Maroof Mandal

Reputation: 531

This has fixed the issue:

        final SwipeRefreshLayout swipeLayout = (SwipeRefreshLayout)this.findViewById(R.id.swipeToRefresh);
        swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                myWebView.reload(); // refreshes the WebView

                if (null != swipeLayout) {
                    swipeLayout.setRefreshing(false);
                }
            }
        });

Upvotes: 2

Omkar
Omkar

Reputation: 3100

more precisely you try code

if (swipeLayout.isRefreshing()) {
    swipeLayout.setRefreshing(false);
}

Upvotes: 1

Mahesh Gawhane
Mahesh Gawhane

Reputation: 338

Set visibility gone to progressBar inside your seOnRefreshListner and stop refreshing swipeLayout after webview is loaded.

  swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {  
  @Override public void onRefresh() { // Insert your code here
      ProgressBar. SetVisibility(GONE); 
      if(null != swipeLayout) {
           swipeLayout.setRefreshing(false);
      }          
      myWebView.reload(); // refreshes the WebView 
  } });

Upvotes: 0

Related Questions