title: how to set date in Datepicker dialog from edittext android?
body: <p>I have a <code>datepicker</code> dialog which put in an <code>edittext</code> to set birthday .. the dialog after setting the date return the current date .. what I need is to display the date I selected to the <code>datepicker</code> dialog after choose it?</p>
  
  <p>The <code>Datepicker</code> dialog class:</p>
  
  <pre><code>    public class DatePickerDialog2 extends DialogFragment{
  
  public static final String ARG_DEFAULT = "default";
  
  private DatePicker datePicker;
  private String defaultDate;
  
      private DatePickerDialog.OnDateSetListener onDateListener;
  public DatePickerDialog2() {
      try {
          OnDatePickerDoneButtonClickedListener act = (OnDatePickerDoneButtonClickedListener) getActivity();
  
      } catch (ClassCastException e) {
          throw new ClassCastException("Must implement OnDatePickerDoneButtonClickedListener");
      }
  }
  
  
      public interface OnDatePickerDoneButtonClickedListener {
      void OnDatePickerDoneButtonClicked(String date);
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      defaultDate = getArguments().getString(ARG_DEFAULT);
  
  }
  
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
       Calendar calendar = Calendar.getInstance();
      if (TextUtils.isEmpty(defaultDate)) {
          DateFormat df = new SimpleDateFormat("dd/MMM/yyyy");;
          try {
              calendar.setTime(df.parse(new Date().toString()));
              Log.d("first", defaultDate + " -");
          } catch (ParseException e) {
              e.printStackTrace();
          }
  
      } else {
          try {
              DateFormat df =  new SimpleDateFormat("dd/MMM/yyyy");
              calendar.setTime(df.parse(defaultDate));
              Log.d("second", defaultDate + " -");
          } catch (ParseException e1) {
              Log.d("third",defaultDate+" -");
          }
      }
      datePicker = new DatePicker(getActivity());
  
      datePicker.setCalendarViewShown(false);
      datePicker.setMaxDate(new Date().getTime()-1 * 24 * 3600 * 1000);
      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
      builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int id) {
  
  //            String date =datePicker.getYear()+ "-"+ datePicker.getDayOfMonth() + "-" + (datePicker.getMonth() + 1)   ;
              int day = datePicker.getDayOfMonth();
              int month = datePicker.getMonth();
              int year =  datePicker.getYear();
  
           final Calendar calendar = Calendar.getInstance();
              calendar.set(year, month, day);
              SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy");
              String date = sdf.format(calendar.getTime());
              OnDatePickerDoneButtonClickedListener act = (OnDatePickerDoneButtonClickedListener) getActivity();
              act.OnDatePickerDoneButtonClicked(date);
              dismiss();
          }
      })
              .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
                      dismiss();
                  }
              })
                      //.setTitle("Select date")
              .setView(datePicker);
      // Create the AlertDialog object and return it
      return builder.create();
  
  }
  }
  </code></pre>
  
  <p>The <code>edittext</code> which i call the dialog to open the datepicker:</p>
  
  <pre><code>  birthday.setOnClickListener(new View.OnClickListener() {
                                 @Override
                                 public void onClick(View v) {
                                     DatePickerDialog2 dialog = new DatePickerDialog2();
                                     Bundle bundle = new Bundle();
                                     bundle.putString("dateAsText", birthday.getText().toString());
                                     dialog.setArguments(bundle);
                                     dialog.show(getSupportFragmentManager(), "date_picker_frag");
                                 }
                             });
  </code></pre>