title: Get date from datepicker using dialogfragment
body: <p>I'm using the google example to insert a datepicker inside my app using a dialogfragment<br>
  <a href="http://developer.android.com/guide/topics/ui/controls/pickers.html">http://developer.android.com/guide/topics/ui/controls/pickers.html</a></p>
  
  <p>But I'm not sure how to get date after set it (not java expert). Dialog and datepicker runs ok and I can log that date is correctely set but, how can i do to get a callback executed on parent activity?</p>
  
  <p>This is my Dialog fragment</p>
  
  <pre><code>public class DatePickerFragment extends DialogFragment implements
          DatePickerDialog.OnDateSetListener {
  
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState) {
          // Use the current date as the default date in the picker
          final Calendar c = Calendar.getInstance();
          int year = c.get(Calendar.YEAR);
          int month = c.get(Calendar.MONTH);
          int day = c.get(Calendar.DAY_OF_MONTH);
  
          // Create a new instance of DatePickerDialog and return it
          return new DatePickerDialog(getActivity(), this, year, month, day);
      }
  
      public void onDateSet(DatePicker view, int year, int month, int day) {
          **Log.w("DatePicker","Date = " + year);**
      }
  }
  </code></pre>
  
  <p>...and I call dialog from my activity with...</p>
  
  <pre><code>public void showDatePickerDialog(View v) {
      DialogFragment newFragment = new DatePickerFragment();
      newFragment.show(getSupportFragmentManager(), "datePicker");
  }
  </code></pre>
  
  <p>What is the correct way to call a method in my parent activity instead Log.w? I suppose that is something related with passing a callback as parameter or something but most of references I found on internet are about previous versions without dialogfragments</p>
  
  <p>EDIT: not sure if it's important but parent activity is declared as:</p>
  
  <pre><code>public class EditSessionActivity extends FragmentActivity {
  </code></pre>
  
  <p><strong>SOLUTION: thanks to Lecho user this is the way to do it</strong></p>
  
  <p>DatePickerFragmennt.class</p>
  
  <pre><code>public class DatePickerFragment extends DialogFragment{
  
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState) {
          // Use the current date as the default date in the picker
          final Calendar c = Calendar.getInstance();
          int year = c.get(Calendar.YEAR);
          int month = c.get(Calendar.MONTH);
          int day = c.get(Calendar.DAY_OF_MONTH);
  
          // Create a new instance of DatePickerDialog and return it
          return new DatePickerDialog(getActivity(), (EditSessionActivity)getActivity(), year, month, day);
      }
  
  }
  </code></pre>
  
  <p>...and parent activity EditSessionActivity.class...</p>
  
  <pre><code>public class EditSessionActivity extends FragmentActivity implements OnDateSetListener {
  ...
      @Override
      public void onDateSet(DatePicker view, int year, int month, int day) {
          //do some stuff for example write on log and update TextField on activity
          Log.w("DatePicker","Date = " + year);
          ((EditText) findViewById(R.id.tf_date)).setText("Date = " + year);
      }
  </code></pre>