Reputation: 28121
I read this document but don't understand.
It says I can use showDialog() to show a dialog and the system will call onDialogCreate().
But in the next section, it says I should use AlertDialog.Builder's create() to create a dialog.
I tried AlertDialog.Builer's show(), it works and a dialog popup. But... so where should I call showDialog() and onDialogCreate()?
Upvotes: 0
Views: 2669
Reputation: 3319
Lai Yu-hsuan.... They are saying that you may use AlertDialog.Builder.create to create a dialog and showDialog(int) to show the dialog that you create using myBuilder.create(). So in code:
protected Dialog onCreateDialog(int id) {
Dialog dialog;
switch(id) {
case DIALOG_MY:
// do the work to define My Dialog
dialog= getInstanceMyDialog();
break;
default:
dialog = null;
break;
}
return dialog;
}
private AlertDialog getInstanceMyDialog() {
AlertDialog.Builder builder= new AlertDialog.Builder(this);
builder.setMessage("MyMessage");
AlertDialog alert= builder.create();
alert.setTitle("MyTitle");
return alert;
}
You can then show the dialog as in:
this.showDialog(DIALOG_MY);
JAL
Upvotes: 1