Code example for AlertDialog.Builder

Methods: create, setMessage, setView

0
 
    @Override 
    public Dialog onCreateDialog(Bundle savedInstanceState) {
 
        // Use the Builder class for convenient dialog construction 
        Builder builder = new AlertDialog.Builder(activity);
 
        // Set the layout for the dialog 
        builder.setView(mView);
 
        // Set title of dialog 
        builder.setMessage("Set Date")
                // Set Ok button 
                .setPositiveButton("Set",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // User ok the dialog 
                            } 
                        }) 
                // Set Cancel button 
                .setNegativeButton("Cancel",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // User cancelled the dialog 
                                DateTimeDialogFragment.this.getDialog().cancel();
                            } 
                        });  
 
        // Create the AlertDialog object and return it 
        return builder.create();
    } 
 
    @Override 
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
Experience pair programming with AI  Get Codota for Java