user751786
user751786

Reputation: 75

How to display an image in Dialog Box

This code will display the dialog box with "Hello World" but I want to display an image like : enter image description here also in the same dialog box.

can anyone help me?

private void showDialog(String message)
{
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Hello World");
    builder.setCancelable(false);
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener()
    {
        public void onClick(DialogInterface dialog, int id)
        {
            dialog.dismiss();
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}

Upvotes: 4

Views: 31767

Answers (3)

Anish Abraham
Anish Abraham

Reputation: 1

private void showDialog(String message)
{
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setMessage("Hello World");
      builder.setIcon(R.drawable.hello);
      builder.setCancelable(false);
      builder.setPositiveButton("OK", new DialogInterface.OnClickListener()
      {
          public void onClick(DialogInterface dialog, int id)
          {
               dialog.dismiss();
           }
      });
            AlertDialog alert = builder.create();
            alert.show();
 }

Upvotes: 0

Dinesh Sharma
Dinesh Sharma

Reputation: 11571

Use CustomDialog instead of the default one.

Checkout this for customDialog: http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application

Hope this will solve your issue.

Upvotes: 2

TeaCupApp
TeaCupApp

Reputation: 11452

Here is the link which will get you to the tutorial about how to do this...

http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog

Enjoy!

Advice:

Search this website you can find most of basic fundamentals http://developer.android.com

Suggestion:

HIT four time space bar before writing any code...it will attract more people to answer your question as it will look well written

Happy Coding!

Upvotes: 4

Related Questions