0

I am trying to set up a pull to refresh feature like chrome (swipe refresh layout). The loading bar disappears after pull. How can i fix this?

I've tried various code samples from stack overflow... but none of them seem to work. Swipe to refresh works but disappears right after pull.

Swipe refresh in main activity java

mySwipeRefreshLayout = this.findViewById(R.id.swipeContainer);

        mySwipeRefreshLayout.setOnRefreshListener(
                new SwipeRefreshLayout.OnRefreshListener() {
                    @Override
                    public void onRefresh() {
                        browser.reload();
                        mySwipeRefreshLayout.setRefreshing(false);
                    }
                }
        );

I Just want the loading icon to load till the full page is refreshed like chrome.

Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
ADITYA G
  • 13
  • 6

1 Answers1

0

if you want to keep the loading till the page loaded you don't have to use mySwipeRefreshLayout.setRefreshing(false) inside your refresh listener , because your are disabling it just after the refresh start.

instead you have to use it when your loading is done . let say as example you have a webview , so you should listen on the webview progress like this example :

mWebView.setWebViewClient(new WebViewClient() {
   public void onPageFinished(WebView view, String url) {
          mySwipeRefreshLayout.setRefreshing(false);
    }
});
ismail alaoui
  • 5,748
  • 2
  • 21
  • 38
  • Hey, also is there a way to add a progress bar while loading... Just like chrome? – ADITYA G May 31 '19 at 05:59
  • Hi @ADITYAG if this or any answer has solved your question please consider accepting it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. for the progressbar check this link https://stackoverflow.com/questions/2537454/android-webview-progress-bar – ismail alaoui May 31 '19 at 13:17