---
title: "Create  alert  dialog box in android."  
description: "Create  alert  dialog box in android."  
author: "Arti Mishra"  
published: 2018-11-05  
updated: 2018-11-05  
canonical: https://www.mindstick.com/forum/34699/create-alert-dialog-box-in-android  
category: "android apps"  
tags: ["android"]  
reading_time: 2 minutes  

---

# Create  alert  dialog box in android.

How to create [alert](https://answers.mindstick.com/qa/30927/what-is-an-alert) [dialog](https://www.mindstick.com/forum/562/jquery-dialog-box-not-closed-in-asp-dot-net-mvc-4) box in android

## Replies

### Reply by Arti Mishra

**First Create a Button in your XML file.(activity_main.xml)**\

<Button

android:id="@+id/show_alert"\

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Show Alert"

android:textSize="@dimen/text_size" />

\

## Code for alert Dialog box

## MainActvity.java

```
..................................................Button showAlert=(Button) findViewById(R.id.show_alert);holder.showAlert.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog.Builder builder1 = new AlertDialog.Builder(mContext);
                builder1.setMessage("Hello I'm Alert Box");
                builder1.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int ids) {
                        if (Utils.isNetworkAvailable(mContext)) {
                          ...............
                          ....................// Write Your Code here
                           .......................
                        } else {
                            Toast.makeText(mContext, mContext.getString(R.string.no_internet), Toast.LENGTH_SHORT).show();
                        }
                    }
                });
                builder1.setNegativeButton("No", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
                builder1.show();
            }
        });
.......................................
```

\

## "Thanks!!! for Reading"


---

Original Source: https://www.mindstick.com/forum/34699/create-alert-dialog-box-in-android

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
