Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
937 B
1
Indexable
Never
public class MyActivity extends AppCompatActivity {
    private boolean isDialogShowing = false;

    // Method to show your dialog
    private void showDialog() {
        if (!isDialogShowing) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("My Dialog")
                   .setMessage("This is a dialog message.")
                   .setPositiveButton("OK", (dialog, which) -> {
                       // Handle positive button click
                   })
                   .setNegativeButton("Cancel", (dialog, which) -> {
                       // Handle negative button click
                   })
                   .setOnDismissListener(dialog -> isDialogShowing = false); // Update flag when dialog dismissed
            AlertDialog dialog = builder.create();
            dialog.show();
            isDialogShowing = true; // Update flag when dialog shown
        }
    }
}
Leave a Comment