[ACCEPTED]-How to check is a dialog opened or not ?-android
Accepted answer
You should put this code in every activity 1 that you want to support this feature.
public AlertDialog myAlertDialog;
public void showDialog(Context context) {
if( myAlertDialog != null && myAlertDialog.isShowing() ) return;
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Title");
builder.setMessage("Message");
builder.setPositiveButton("ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int arg1) {
dialog.dismiss();
}});
builder.setCancelable(false);
myAlertDialog = builder.create();
myAlertDialog.show();
}
Rewrite your method to return AlertDialog
, assign it 6 to a member and check before invoking this 5 method if it's null or !isShowing()
.
You could also 4 use onCreateDialog
instead. Implement this method in base 3 class for your activities that needs the 2 dialog managing and then call showDialog(int id)
wherever 1 you want.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.