Search This Blog

Sunday 3 June 2012

Alert Message Box in Android


Creating  Alert Message Box in Android needs a bit of coding. Here is a sample code for  simple alert dialog using Dialog Builder.

Alert dialog extends the dialog and provides a easy method to create a message box in android.

 
 AlertDialog.Builder builder = new AlertDialog.Builder(this);  
         builder.setMessage("Title Here");  
         builder.setMessage("Message here")  
             .setCancelable(false)  
             .setPositiveButton("Yes", new DialogInterface.OnClickListener() {  
               public void onClick(DialogInterface dialog, int id) {  
               // TODO : Add Action code for yes button
               }  
             })  
             .setNegativeButton("No", new DialogInterface.OnClickListener() {  
               public void onClick(DialogInterface dialog, int id) {  
                 dialog.cancel();  
               }  
             });  
         AlertDialog alert = builder.create();  
         alert.show();   

No comments:

Post a Comment