- 论坛徽章:
- 0
|
- 1、AlertDialog创建流程:
- 先是创建AlertDialog.Builder对象,然后设置此对象,最后调用create()方法创建AlertDialog
- 2、AlertDialog.Builder的方法:
- setPositiveButton
- setNeutralButton
- setNegativeButton
- setMessage
- setItems
- setSingleChoiceItems
- setMultiChoiceItems
之上这四个,同一个Builder只能调用一次,不可以共存
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.
- 创建完AlertDialog后是不显示的,要想显示需再调用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();
|
|