Alert Dialog in Android

A Dialog is small window that prompts the user to a decision or enter additional information.The AlertDialog class allows you to build a variety of dialog designs and is often the only dialog class you'll need.
  1. Title This is optional and should be used only when the content area is occupied by a detailed message, a list, or custom layout. If you need to state a simple message or question you don't need a title.
  2. Content area This can display a message, a list, or other custom layout.
  3. Action buttons There should be no more than three action buttons in a dialog.

    for details click here

    Example :
     
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
          alertDialogBuilder.setMessage("Are you sure,
             You want to exit");
          alertDialogBuilder.setPositiveButton("yes", 
             new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface arg0, int arg1) {
                Toast.makeText(context,"You clicked yes 
                   button",Toast.LENGTH_LONG).show();
             }
          });
    
          alertDialogBuilder.setNegativeButton("No",new DialogInterface.OnClickListener() {
             Override
             public void onClick(DialogInterface dialog, int which) {
                finish();
             }
          });
    
          AlertDialog alertDialog = alertDialogBuilder.create();
          alertDialog.show();


Find us :
        Facebook : @apnaandroid
        Google+   : Apna Java
        Youtube : Android & Java Tutorial

Output :

             

Comments

Popular posts from this blog

Disable/Hide Year from DatePickerDialog in android

Custom Calendar in android

Coordinator Layout in Android