Android:dialog box issue
I use the Progress Dialog ,first time when I load the web view and create the object in OnCreate
progressBar = new ProgressDialog(this);
progressBar.setCancelable(true);
progressBar.setMessage("Loading...");
progressBar.setOnCancelListener(new OnCancelListener() {
public void onCancel(DialogInterface arg0) {
if (progressBar.isShowing())
progressBar.dismiss();
finish();
}
});
progressBar.show();
and dismiss it onPageFinished
public void onPageFinished(WebView view, String url) {
Log.i("TEST", "Finished loading URL: " + url);
if (progressBar.isShowing()) {
progressBar.dismiss();
}
}
then I load another url fr开发者_开发百科om menu then I write the code in onPageStarted
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
if(progressBar.isShowing()){}
else
//progressBar.
progressBar.show();
super.onPageStarted(view, url, favicon);
}
on second time the circle in Dialog is not running, all everything works fine. you can view same problem in ApiDemos alos. please install Apidemos application in device then go to view->progress bar->dialog->click on "show Intermediat" then dismiss using back button.Now add click on same button, the circle animation will working
Thanks in Advance.
This is issue is related to activity because when we dismiss the dialog activity store it value so second time call it load the same state of dialog so need to implement the onPrepareDialog for resetting the new value and use the removeDialog(int) just before the showing. please check it out ProgressBar does not reset to "0" when opening the second time
code here
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
switch (id) {
case DIALOG_WEBVIEW:
progressBar.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressBar.setMessage("Loading...");
progressBar.setCancelable(true);
//mProgressDialog.show();
return;
default:
return ;
}
//super.onPrepareDialog(id, dialog);
}
for onCreateDialog
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_WEBVIEW:
progressBar = new ProgressDialog(this);
progressBar.show();
return progressBar;
default:
return null;
}
}
lastly to show,dismiss and remove like this
removeDialog(DIALOG);
showDialog(DIALOG);
dismissDialog(DIALOG);
精彩评论