Code for open date picker dialog in android.

Posted by  Arti Mishra
 1207  View(s)
Rate this:

Code for open date picker dialog(Calendar) in android after clicking on EditText.

  1. Re: Code for open date picker dialog in android.

    /* get Instance of calendar */ 

    Calendar myCalendar = Calendar.getInstance();

    /* Create object of EditText. */

    EditText dateOfBirth = (EditText) findViewById(;

       /* Set value on date objects*/ 

            final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {


                public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {

                    myCalendar.set(Calendar.YEAR, year);

                    myCalendar.set(Calendar.MONTH, monthOfYear);

                    myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);




     private void updateLabel() {

            String myFormat = "yyyy-MM-dd"; //In which you need put here

            SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);



     /* open Date Picker Dialog for dob*/

            dateOfBirth.setOnClickListener(new View.OnClickListener() {


                public void onClick(View view) {

                    new DatePickerDialog(EditProfileActivity.this, date, myCalendar

                            .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)).show();