How Can I Close A Progressdialog After A Set Time?
I am trying to close a ProgressDialog box automatically after 3 seconds. Here is the dialog: ProgressDialog progress = new ProgressDialog(this); progress.setTitle('Connecting'); pr
Solution 1:
AsyncTask is okay if you are processing a long running task and then want to cancel it after, but it's a bit overkill for a 3 second wait. Try a simple handler.
finalProgressDialogprogress=newProgressDialog(this);
progress.setTitle("Connecting");
progress.setMessage("Please wait while we connect to devices...");
progress.show();
RunnableprogressRunnable=newRunnable() {
@Overridepublicvoidrun() {
progress.cancel();
}
};
HandlerpdCanceller=newHandler();
pdCanceller.postDelayed(progressRunnable, 3000);
Updated adding show/hide:
progress.setOnCancelListener(newDialogInterface.OnCancelListener() {
@OverridepublicvoidonCancel(DialogInterface dialog) {
theLayout.setVisibility(View.GONE);
}
});
Post a Comment for "How Can I Close A Progressdialog After A Set Time?"