- 論壇徽章:
- 0
|
- 1、AlertDialog創(chuàng)建流程:
- 先是創(chuàng)建AlertDialog.Builder對象,然后設(shè)置此對象,最后調(diào)用create()方法創(chuàng)建AlertDialog
- 2、AlertDialog.Builder的方法:
- setPositiveButton
- setNeutralButton
- setNegativeButton
- setMessage
- setItems
- setSingleChoiceItems
- setMultiChoiceItems
之上這四個,同一個Builder只能調(diào)用一次,不可以共存
public
AlertDialog
create
()
Creates a AlertDialog with the arguments supplied to this builder. It does not
show() the dialog. This allows the user to do any extra processing
before displaying the dialog. Use show() if you don't have any other processing
to do and want this to be created and displayed.
- 創(chuàng)建完AlertDialog后是不顯示的,要想顯示需再調(diào)用show()方法。
- 3、舉例:
- new AlertDialog.Builder(AlertDialogSamples.this)
-
.setIcon(R.drawable.ic_popup_reminder)
-
.setTitle(R.string.alert_dialog_multi_choice)
-
.setMultiChoiceItems(R.array.select_dialog_items3,
-
new boolean[]{false, true, false, true, false, false, false},
-
new DialogInterface.OnMultiChoiceClickListener() {
-
public void onClick(DialogInterface dialog, int whichButton,
-
boolean isChecked) {
-
-
/* User clicked on a check box do some stuff */
-
}
-
})
-
.setPositiveButton(R.string.alert_dialog_ok,
-
new DialogInterface.OnClickListener() {
-
public void onClick(DialogInterface dialog, int whichButton) {
-
-
/* User clicked Yes so do some stuff */
-
}
-
})
-
.setNegativeButton(R.string.alert_dialog_cancel,
-
new DialogInterface.OnClickListener() {
-
public void onClick(DialogInterface dialog, int whichButton) {
-
-
/* User clicked No so do some stuff */
-
}
-
})
-
.create();
|
|