Android prompt dialog

The dialog box is implemented using the Dialog class. Among them, Alertialog is used to implement a warning dialog; ProgressDialog is used to implement a dialog with a progress bar; DatePickerDialog is used to implement a date selection dialog; TimePickerDialog is used to implement a time selection dialog.


1.AlertDialog.Builder category


  in Android development, the warning dialog can be achieved through the use of custom AlertDialog.Builder class. When using the AlertDialog.Builder class to create a dialog box, you usually need to use the following common methods:


  (1) setTitle (); // Set the dialog box title 


  (2) setIcon (); // Set the dialog box icon 


  (3 )


  SetMessage (); // Set the content of the dialog box  (4) setItems (); // Set the list of items to be displayed in the dialog box 


  (5) setView (); // Set the custom dialog style 


  (6) setSingleChoiceItems (); // The setting dialog box displays a radio box


  (7) setMultiChoiceItems (); // The setting dialog box displays a series of check boxes 


  (8) setPositiveButton (); // The setting dialog box displays a "OK" button 


  (9) setNeutralButton (); // The setting dialog box displays an "exit" button 


  (10) setNegativeButton (); // Set the dialog box to display a "Cancel" button


  (11) create (); // Create an AlertDialog dialog box


  (12) show (); // Display the dialog box






new AlertDialog.Builder (XiuGaiActivity .this) .setTitle ("Whether to delete")
.setPositiveButton("确定",new DialogInterface.OnClickListener() {

@Override  
public void onClick (DialogInterface dialog, int which) {// OK button response event  
 
            // TODO Auto-generated method stub  
  Determine response time
BookDAO dao = new BookDAO (XiuGaiActivity.this);
int id = (int) getIntent().getLongExtra("id", -1);
dao.detele (id);
setResult (0);
finish();  
        }  
}).setNegativeButton("返回",new DialogInterface.OnClickListener() {

@Override  
        public void onClick(DialogInterface dialog, int which) {
// finish();
}
}). show (); // To display this dialog box in the key response event








Toast is a short message prompt:


makeText (Context context, CharSequence text, int duration)


context: the context of the call, usually Application or Activity object


text: The displayed message


duration: the length of time displayed, which is Toast.LENGTH_LONG or Toast.LENGTH_SHORT
Published 18 original articles · praised 4 · 40,000+ views

Guess you like

Origin blog.csdn.net/caoming51021/article/details/44411491