AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Alert"); builder.setMessage("Do you want to continue?"); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // do something when Yes button is clicked } }); builder.setNegativeButton("No", null); builder.show();
private void showDatePickerDialog() { DatePickerDialog datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { // perform action when date is selected } }, year, month, day); datePickerDialog.setTitle("Select Date"); datePickerDialog.show(); }In this example, a DatePickerDialog is displayed to select a date. The setTitle method is used to set the title of the dialog as "Select Date". The package library for the AlertDialog.Builder class is android.app.