Date Picker Dialog

suggest change

The dialog prompts the user to select a date with a DatePicker. It needs a context and the initial year, month, and day. The selected date comes back through DatePickerDialog.OnDateSetListener.

public void showDatePicker(Context context, int initialYear, int initialMonth, int initialDay) {
    DatePickerDialog datePickerDialog = new DatePickerDialog(context,
            new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker datepicker, int year, int month, int day) {
                    // onDateSet can run twice on some versions. Ignore the call after the picker is gone.
                    if (datepicker.isShown()) {
                        // You now have the selected year, month, and day.
                    }
                }
            }, initialYear, initialMonth, initialDay);

    datePickerDialog.show();
}

Month is an int from 0 for January through 11 for December.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents