Here is my code -
View layout = LayoutInflater.from(this).inflate(R.layout.dialog_loc_info, null);
final Button mButton_Mobile = (Button) layout.findViewById(R.id.button);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(layout);
mButton_Mobile.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(builder.)
showDialog(); // this is another dialog, nothing to do with this code
}
});
builder.setNeutralButton(getString(android.R.string.ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.show();
You can use AlertDialog
methods for that.
AlertDialog alert = new AlertDialog.Builder(context).create();
if (alert.isShowing()) {
alert.dismiss();
}
Hope it helps.
An alternative approach is to use a method to generate the AlertDialog with a builder and then create the AlertDialog without showing it while setting the AlertDialog to a class variable.
Then check with .isShowing();
method
Example:
AlertDialog mAlertDialog;
public showMyAlertDialog(View layout){
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setView(layout);
builder.setNeutralButton(getString(android.R.string.ok),new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
mAlertDialog = null; //setting to null is not required persay
}
});
mAlertDialog = builder.create()
mAlertDialog.show();
}
public boolean isAlertDialogShowing(AlertDialog thisAlertDialog){
if(thisAlertDialog != null){
return thisAlertDialog.isShowing();
}
}
hope that it is understood how to use this source. cheers
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