Question about harder challenge


Since we needed two dialogs, I created another DialogFragment called PickerDialogFragment to choose between time and date. Both of those are also fragments though I’m not sure if that’s the best way to do it. My problem is that I’m managing those two fragments (time and date) in PickerDialogFragment based on a radio buttons, but I need the time and date fragments to have access to model data in CrimeFragment. Maybe I’m approaching this challenge the wrong way. Any thoughts?


You could still use the target mechanism, similar to what is described in the chapter.

Let’s say that the user selects the Date picker. It would work something like this:

1- Start PickerDialogFragment, initializing it with mCrime’s date and setting CrimeFragment to be its target
2- User selects the Date picker.
3- PickerDialogFragment starts up DatePickerDialogFragment, setting the DatePickerDialogFragment’s target to be its own target - like this:

DatePickerFragment dialog = DatePickerFragment.newInstance(mDate);
dialog.setTarget(getTargetFragment(), getTargetRequestCode());, DIALOG_DATE);

Does that give you some idea of the approach? Let me know if I need to clarify more than that.


I tried your outlined suggestions and I got it to work! Thanks for the help!
Quick question though. I was trying to work with the Date class but almost all of its methods are deprecated, so I had to use Calendar instead. Why is this so?
Thanks again.


Date used to include a lot of wall-calendar type code in older versions of Java. Java designers soon realized that this was a bad idea - a Date is a point in time, but that point in time can be a different calendar date depending on which calendar you use. So they got rid of the calendar methods on Date and created Calendar.