Alert Dialog Box in Android

In Android whenever we need to create alert in application, at that time we can use Alert Dialog. Alert Dialog box is a simple prompt message window for provide alert to user.

Alert Dialog provide three king of buttons like Positive(like OK,Yes,Done),Negative(like No,Delete,Cancel) and Neutral(like Cancel,Help). Using this buttons we can able to perform any actions. You may able use any button as per requirement, not necessary to use all button at time.

To create Alert Dialog, we need AlertDialogBuilde class.

Components of Alert Dialog :

  • Title : Title of Alert Dialog.
  • Content : Display message of Alert.
  • Action Buttons :  Perform any action from alert dialog from three buttons.

To customize Alert Dialog we can use below methods,

  • setTitle() : To set title of Alert dialog.
  • setMessage() : To set message or descriptions of alert to user.
  • setCancelable() : To set is dialog is cancelable or not.
  • setIcon() : To set Alert Dialog Icon.
  • setMultiChoiceItems() : To sets list of items to be displayed in the dialog as the content. The selected option will be notified by the listener.

Lets see one simple example


Now run Project. Our output looks like below


Download Project.

Now see next tutorial Custom Alert Dialog in Android.

(Visited 568 times, 1 visits today)