# 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 %}
