How can I show the progress bar while loading data into my webview? My code :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_PROGRESS);
getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
this.setProgressBarVisibility(true);
setContentView(R.layout.layout_article);
WebView webview = (WebView) findViewById(R.id.webView);
final Activity activity = this;
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
activity.setProgress(progress * 100);
}
});
webView.loadUrl("http://google.com");
}
Before calling loadData() function, just try to show ProgressDialog or put ProgressBar inside layout.
And inside the WebViewClient, just dismiss() the progressDialog or make the ProgressBar invisible.
for example:
// when finish loading page
public void onPageFinished(WebView view, String url) {
if(mProgress.isShowing()) {
mProgress.dismiss();
}
}
FYI, call loadData() or loadURL() only after you are done with web client setting.
check this example: Load WebView with ProgressDialog
Please try following code,
ProgressDialog progDailog = ProgressDialog.show( context,"Process ", "Loading Data...",true,true);
new Thread ( new Runnable()
{
public void run()
{
// your data loading code goes here
}
}).start();
Handler progressHandler = new Handler()
{
public void handleMessage(Message msg1)
{
progDailog.dismiss();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With