I'm trying to setup a fragment that mainly displays a progress bar
and a
webview
, once the website loads up completely, the progress bar
should disappear. I'm following this code:
https://stackoverflow.com/a/8467430/7803533
The problem is that the OnProgressChanged method is never used:
public class HUB extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_hub, container, false);
final ProgressBar progressBar = (ProgressBar) rootView.findViewById(R.id.pBar);
WebView mWebView = (WebView) rootView.findViewById(R.id.webview);
mWebView.setWebViewClient(new WebViewClient(){
public void onProgressChanged(WebView view, int progress){
if(progress < 100 && progressBar.getVisibility() == ProgressBar.GONE){
progressBar.setVisibility(ProgressBar.VISIBLE);
}
progressBar.setProgress(progress);
if(progress == 100){
progressBar.setVisibility(ProgressBar.GONE);
}
}
});
mWebView.clearCache(true);
mWebView.clearHistory();
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.loadUrl("https:10.10.1.40/index.html");
return rootView;
}
}
Layout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="sykes.moodleapp.HUB">
<!-- TODO: Update blank fragment layout -->
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/pBar"
style="?android:attr/progressBarStyleHorizontal"
android:padding="2dip"/>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webview"
></WebView>
</FrameLayout>