In my app, I have a Fragment that holds a Button showing a DatePickerDialog. I would like to be able to change some aspects of the DatePicker (from DatePickerDialog), before being able to show it to the user (ie. showing only some of the fields (day, month, year) or restricting the dates allowed inside the DatePicker).
I read this possible solution: Android DialogFragment - Get reference to date picker but it doesn't seem to look like the correct way to do it, to me.
Basicly, I need to get a reference of the DatePicker, before calling show() on the DatePickerFragment itself. Any other possible ideas?
Here is some of the code I have so far:
public static GenericDatePickerDialog newInstance(int year, int month, int day) { GenericDatePickerDialog frag = new GenericDatePickerDialog(); Bundle args = new Bundle(); args.putInt(KEY_YEAR, year); args.putInt(KEY_MONTH, month); args.putInt(KEY_DAY, day); frag.setArguments(args); return frag; } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle args = getArguments(); mYear = args.getInt(KEY_YEAR); mMonth = args.getInt(KEY_MONTH); mDay = args.getInt(KEY_DAY); mDatePickerDialog = new DatePickerDialog(getActivity(), mCallback, mYear, mMonth, mDay); return mDatePickerDialog; } public void setRestrictionOnDate(boolean restrictMax, long time) { ... } public void hideDpFields() { ... }