Source:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.date_picker_dialog, null); Button mSetButton = (Button) view.findViewById(R.id.done_button); Button mCancelButton = (Button) view.findViewById(R.id.cancel_button); mCancelButton.setTextColor(mTextColor); mCancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dismiss(); } }); mSetButton.setTextColor(mTextColor); mSetButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { for (DatePickerDialogHandler handler : mDatePickerDialogHandlers) { handler.onDialogDateSet(mReference, mPicker.getYear(), mPicker.getMonthOfYear(), mPicker.getDayOfMonth()); } final Activity activity = getActivity(); final Fragment fragment = getTargetFragment(); if (activity instanceof DatePickerDialogHandler) { final DatePickerDialogHandler act = (DatePickerDialogHandler) activity; act.onDialogDateSet(mReference, mPicker.getYear(), mPicker.getMonthOfYear(), mPicker.getDayOfMonth()); } else if (fragment instanceof DatePickerDialogHandler) { final DatePickerDialogHandler frag = (DatePickerDialogHandler) fragment; frag.onDialogDateSet(mReference, mPicker.getYear(), mPicker.getMonthOfYear(), mPicker.getDayOfMonth()); } dismiss(); } }); mPicker = (DatePicker) view.findViewById(R.id.date_picker); mPicker.setSetButton(mSetButton); mPicker.setDate(mYear, mMonthOfYear, mDayOfMonth); mPicker.setTheme(mTheme); getDialog().getWindow().setBackgroundDrawableResource(mDialogBackgroundResId); return view; }

Target:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.date_picker_dialog, null); Button doneButton = (Button) view.findViewById(R.id.done_button); Button cancelButton = (Button) view.findViewById(R.id.cancel_button); cancelButton.setTextColor(mTextColor); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dismiss(); } }); doneButton.setTextColor(mTextColor); doneButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { for (DatePickerDialogHandler handler : mDatePickerDialogHandlers) { handler.onDialogDateSet(mReference, mPicker.getYear(), mPicker.getMonthOfYear(), mPicker.getDayOfMonth()); } final Activity activity = getActivity(); final Fragment fragment = getTargetFragment(); if (activity instanceof DatePickerDialogHandler) { final DatePickerDialogHandler act = (DatePickerDialogHandler) activity; act.onDialogDateSet(mReference, mPicker.getYear(), mPicker.getMonthOfYear(), mPicker.getDayOfMonth()); } else if (fragment instanceof DatePickerDialogHandler) { final DatePickerDialogHandler frag = (DatePickerDialogHandler) fragment; frag.onDialogDateSet(mReference, mPicker.getYear(), mPicker.getMonthOfYear(), mPicker.getDayOfMonth()); } dismiss(); } }); mPicker = (DatePicker) view.findViewById(R.id.date_picker); mPicker.setSetButton(doneButton); mPicker.setDate(mYear, mMonthOfYear, mDayOfMonth); mPicker.setTheme(mTheme); getDialog().getWindow().setBackgroundDrawableResource(mDialogBackgroundResId); return view; }