android alertdialog

Report
Question
746 views

Android AlertDialog can be used to display the dialog message with OK and Cancel buttons. It can be used to interrupt and ask the user about his/her choice to continue or discontinue.

Please explain why do you think this question should be reported?

Report Cancel

Android AlertDialog is composed of three regions: title, content area and action buttons.

Android AlertDialog is the subclass of Dialog class.

These methods are used to place the content in all regions.

1. public AlertDialog.Builder setTitle(CharSequence)

2. public AlertDialog.Builder setMessage(CharSequence)

3. public AlertDialog.Builder setIcon(int)

AlertDialog.Builder builder;  

builder = new AlertDialog.Builder(this);  

 

  1. builder.setMessage(R.string.dialog_message) .setTitle(R.string.dialog_title);  
  2.   
  3.                 //Setting message manually and performing action on button click  
  4.                 builder.setMessage("Do you want to close this application ?")  
  5.                         .setCancelable(false)  
  6.                         .setPositiveButton("Yes", new DialogInterface.OnClickListener() {  
  7.                             public void onClick(DialogInterface dialog, int id) {  
  8.                                 finish();  
  9.                                 Toast.makeText(getApplicationContext(),"you choose yes action for alertbox",  
  10.                                 Toast.LENGTH_SHORT).show();  
  11.                             }  
  12.                         })  
  13.                         .setNegativeButton("No", new DialogInterface.OnClickListener() {  
  14.                             public void onClick(DialogInterface dialog, int id) {  
  15.                                 //  Action for 'NO' Button  
  16.                                 dialog.cancel();  
  17.                                 Toast.makeText(getApplicationContext(),"you choose no action for alertbox",  
  18.                                 Toast.LENGTH_SHORT).show();  
  19.                             }  
  20.                         });  
  21.                 //Creating dialog box  
  22.                 AlertDialog alert = builder.create();  
  23.                 //Setting the title manually  
  24.                 alert.setTitle("AlertDialogExample");  
  25.                 alert.show();  

 

Thread Reply

Leave an comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>