Swipe to Refresh in webView in Fragment

时间:2018-04-20 21:29:12

标签: fragment reload

I have a webview inside a fragment and I want to add a swipe to refresh the page. I've been trying a lot but nothing works.

my .xml

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipe"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

</android.support.v4.widget.SwipeRefreshLayout>



<ProgressBar
    android:id="@+id/prgFauna"
    style="?android:attr/progressBarStyle"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_centerHorizontal="true"
    />

and .java

ProgressBar progressBar;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v=inflater.inflate(R.layout.fragment_fauna, container, false);

    progressBar=v.findViewById(R.id.prgFauna);

    final WebView webView=(WebView)v.findViewById(R.id.web_fauna);
    webView.getSettings().setJavaScriptEnabled(true); 
    webView.setWebViewClient(new WebViewClient(){       
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            progressBar.setVisibility(View.VISIBLE);
        }

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

    webView.loadUrl("http://www.vivecolbun.com/fauna.html");

When open the webview(again) it shows me the last view and doesn't reload the url. I don't know why

pleaaaase help me!

0 个答案:

没有答案