日曆應用程序具有代碼來調用EditEventFragment的DatePickerDialog(我認爲)
它看起來大約是這樣的:
private class DateListener implements DatePickerDialog.OnDateSetListener {
View mView;
public DateListener(View view) {
mView = view;
}
@Override
public void onDateSet(DatePickerDialog view, int year, int month, int monthDay) {
// Cache the member variables locally to avoid inner class overhead.
Time startTime = mStartTime;
Time endTime = mEndTime;
// Cache the start and end millis so that we limit the number
// of calls to normalize() and toMillis(), which are fairly
// expensive.
long startMillis;
long endMillis;
if (mView == mFromDateButton) {
startTime.year = year;
startTime.month = month;
startTime.monthDay = monthDay;
startMillis = startTime.normalize(true);
setDate(mFromDateButton, startMillis);
} else {
endTime.year = year;
endTime.month = month;
endTime.monthDay = monthDay;
// Do not allow an event to have an end time before the start
// time.
if (endTime.before(mStartTime)) {
endTime.set(mStartTime);
}
endMillis = endTime.normalize(true);
setDate(mToDateButton, endMillis);
}
}
}
private DatePickerDialog mDatePickerDialog;
private class DateClickListener implements View.OnClickListener {
private Time mTime;
public DateClickListener(Time time) {
mTime = time;
}
@Override
public void onClick(View v) {
final DateListener listener = new DateListener(v);
if (mDatePickerDialog != null) {
mDatePickerDialog.dismiss();
}
mDatePickerDialog = DatePickerDialog.newInstance(listener,
mTime.year, mTime.month, mTime.monthDay);
mDatePickerDialog.setFirstDayOfWeek(PickerUtils.getFirstDayOfWeekAsCalendar(getActivity()));
mDateRangePickerDialog.setYearRange(mToday.year, mToday.year + 2);
mDateRangePickerDialog.show(getActivity().getFragmentManager(), "datePicker");
}
}