Edit Article

In Android, you can add alerts to your application to get the users focus on something, like an update. The AlertDialog class is used to display an alert. You can implement the functionality into your app just by writing a little bit of extra code!

Ad

EditSteps

  1. Show Alert Dialog in Android Step 1.jpg
    1
    Import the AlertDialog class to your Android application.

    import android.app.AlertDialog;
    Ad
  2. Show Alert Dialog in Android Step 2.jpg
    2
    Set up the AlertDialog class to the body of your application like this. Set some properties for the AlertDialog object.

    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle("Reset...");
    alertDialog.setMessage("Are you sure?");
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
    // here you can add functions
    }
    });
    alertDialog.setIcon(R.drawable.icon);
    alertDialog.show();
  3. Show Alert Dialog in Android Step 3.jpg
    3
    Save your application and run. You will get the image as below.
    Ad

We could really use your help!

Can you tell us about
relationships?
Yes
No
relationships
how to get to know a girl
Can you tell us about
New Era hats?
Yes
No
New Era hats
how to clean New Era hats
Can you tell us about
finger biting self-therapy?
Yes
No
finger biting self-therapy
how to stop biting your fingers
Can you tell us about
clothing reuse?
Yes
No
clothing reuse
how to recycle old jeans
Thanks for helping! Please tell us everything you know about
...
Tell us everything you know here. Remember, more detail is better.
Tips
Provide Details.
Please be as detailed as possible in your explanation. Don't worry about formatting! We'll take care of it. For example:
Don't say: Eat more fats.
Do say: Add fats with some nutritional value to the foods you already eat. Try olive oil, butter, avocado, and mayonnaise.

EditVideo



Article Info

Categories: Android

In other languages:

Italiano: Come Visualizzare gli Alert Dialog su Android, Português: Como Exibir uma Caixa de Diálogo com AlertDialog no Android, Español: Cómo mostrar un diálogo de alerta en Android, Русский: отобразить диалоговое окно Alert в Android

Thanks to all authors for creating a page that has been read 179,240 times.

Did this article help you?
Yes No

Become
an Author!

Write an Article