Thursday, January 3, 2013

Android Alert Dialog Example

What are  Alert Dialogs

An Alert Dialog is used to show some information or to prompts the user to make.
Dialogs can also be used to take input from users, such dialogs are called Customized Dialogs.

Buiding  Alert Dialogs:    

 AlertDialog class is used to create Alert Dialog.

Three things are required to create a dialog.
1:Title : The title of the dialog
2: Message: The message to be given in dialog.
3: Image(Optional): Image to displayed in Title Bar


We can also add buttons in Alert Dialog.

Code to create Alert Dialog

AlertDialog dialog;
                dialog = new AlertDialog.Builder(this).create();
                dialog.setTitle("Close");
                dialog.setIcon(android.R.drawable.ic_dialog_info);
                dialog.setMessage("Want to close this App").


dialog.show();


Adding Buttons to Dialog:


dialog.setButton(DialogInterface.BUTTON_POSITIVE, "Yes",
                new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which)
            {
                   
                // Your Code
            }   
        });
        dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "No",
                new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which)
            {
                   
                  // Your Code
            }   
        });
        dialog.show();


Dismissing A dialog 


dialog.dismiss();


9 comments:

  1. Really useful. Thank you!

    ReplyDelete
  2. It seems like I've never seen an article of a kind like . It literally means the best thorn. It seems to be a fantastic article. It is the best among articles related to ๋จนํŠ€๊ฒ€์ฆ์—…์ฒด. seems very easy, but it's a difficult kind of article, and it's perfect.

    ReplyDelete
  3. It’s good to have a website like this. I can read all the opinions of others as well as i gained information to each and everyone here on your site. Just keep on going dude.
    Check over here: ํ† ํ† ์‚ฌ์ดํŠธ

    ReplyDelete
  4. Well I can read all the opinions of others as well as i gained information to each and everyone here on your site. Just keep on going dude. ๊ฒฝ๋งˆ์‚ฌ์ดํŠธ

    ReplyDelete
  5. It was very easy to find my way around and very user friendly Good job to your designer and dev of your site. I hope your rate was doing well. ํ† ํ† 

    ReplyDelete
  6. That's a really impressive new idea! ์•ˆ์ „ํ•œ๋†€์ดํ„ฐ It touched me a lot. I would love to hear your opinion on my site. Please come to the site I run once and leave a comment. Thank you.

    ReplyDelete
  7. I am very impressed with your writing casino online I couldn't think of this, but it's amazing! I wrote several posts similar to this one, but please come and see!

    ReplyDelete
  8. Hi,
    Thanks for sharing the information with us it was very informative. https://hangup.in

    ReplyDelete