> For the complete documentation index, see [llms.txt](https://jobinjj.gitbook.io/tutorials/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jobinjj.gitbook.io/tutorials/menus-and-pickers/alert-dialog.md).

# Alert dialog

**Code**

{% code title="MainActivity.java" %}

```java
AlertDialog.Builder myAlertBuilder = new
        AlertDialog.Builder(MainActivity.this);
myAlertBuilder.setTitle(R.string.alert_title);
myAlertBuilder.setMessage(R.string.alert_message);
myAlertBuilder.setPositiveButton("OK", new
        DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                
            }
        });
myAlertBuilder.setNegativeButton("Cancel", new
        DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                
            }
        });
AlertDialog alertDialog = myAlertBuilder.create();
alertDialog.show();
```

{% endcode %}
