DatePickerDialog is loaded into the Snippet, which today displays as the default date when the dialog opens. Then the user selects the date, and then the dialog is rejected. The next time you reopen, how do I show the previously selected date as the default date, and not show today's date?
I tried .set () in Activity, but don't know how to use .get () to retrieve the date in a fragment. I tried a listener interface between Activity and fragement, but couldn't make it work, and it seems too complicated for the simple task I'm trying to accomplish. And I tried the package sent from Activity to the fragment, but I could not get this to work. Please inform.
Action file:
...
final Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);
c.set(Calendar.DAY_OF_MONTH, day);
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(getSupportFragmentManager(), "datePicker");
Fragment File:
...
public static class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
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);
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
}
}