DatePickerDialogpublic class DatePickerDialog extends AlertDialog implements android.widget.DatePicker.OnDateChangedListener, android.content.DialogInterface.OnClickListenerA simple dialog containing an {@link android.widget.DatePicker}.
See the Pickers
guide. |
Fields Summary |
---|
private static final String | YEAR | private static final String | MONTH | private static final String | DAY | private final android.widget.DatePicker | mDatePicker | private final OnDateSetListener | mDateSetListener | private final Calendar | mCalendar | private boolean | mTitleNeedsUpdate | private final android.widget.DatePicker.ValidationCallback | mValidationCallback |
Constructors Summary |
---|
public DatePickerDialog(android.content.Context context, OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth)
this(context, 0, callBack, year, monthOfYear, dayOfMonth);
| public DatePickerDialog(android.content.Context context, int theme, OnDateSetListener listener, int year, int monthOfYear, int dayOfMonth)
super(context, resolveDialogTheme(context, theme));
mDateSetListener = listener;
mCalendar = Calendar.getInstance();
final Context themeContext = getContext();
final LayoutInflater inflater = LayoutInflater.from(themeContext);
final View view = inflater.inflate(R.layout.date_picker_dialog, null);
setView(view);
setButton(BUTTON_POSITIVE, themeContext.getString(R.string.ok), this);
setButton(BUTTON_NEGATIVE, themeContext.getString(R.string.cancel), this);
setButtonPanelLayoutHint(LAYOUT_HINT_SIDE);
mDatePicker = (DatePicker) view.findViewById(R.id.datePicker);
mDatePicker.init(year, monthOfYear, dayOfMonth, this);
mDatePicker.setValidationCallback(mValidationCallback);
|
Methods Summary |
---|
public android.widget.DatePicker | getDatePicker()Gets the {@link DatePicker} contained in this dialog.
return mDatePicker;
| public void | onClick(android.content.DialogInterface dialog, int which)
switch (which) {
case BUTTON_POSITIVE:
if (mDateSetListener != null) {
mDateSetListener.onDateSet(mDatePicker, mDatePicker.getYear(),
mDatePicker.getMonth(), mDatePicker.getDayOfMonth());
}
break;
case BUTTON_NEGATIVE:
cancel();
break;
}
| public void | onDateChanged(android.widget.DatePicker view, int year, int month, int day)
mDatePicker.init(year, month, day, this);
updateTitle(year, month, day);
| public void | onRestoreInstanceState(android.os.Bundle savedInstanceState)
super.onRestoreInstanceState(savedInstanceState);
final int year = savedInstanceState.getInt(YEAR);
final int month = savedInstanceState.getInt(MONTH);
final int day = savedInstanceState.getInt(DAY);
mDatePicker.init(year, month, day, this);
| public android.os.Bundle | onSaveInstanceState()
final Bundle state = super.onSaveInstanceState();
state.putInt(YEAR, mDatePicker.getYear());
state.putInt(MONTH, mDatePicker.getMonth());
state.putInt(DAY, mDatePicker.getDayOfMonth());
return state;
| static int | resolveDialogTheme(android.content.Context context, int resid)
if (resid == 0) {
final TypedValue outValue = new TypedValue();
context.getTheme().resolveAttribute(R.attr.datePickerDialogTheme, outValue, true);
return outValue.resourceId;
} else {
return resid;
}
| public void | updateDate(int year, int monthOfYear, int dayOfMonth)Sets the current date.
mDatePicker.updateDate(year, monthOfYear, dayOfMonth);
| private void | updateTitle(int year, int month, int day)
if (!mDatePicker.getCalendarViewShown()) {
mCalendar.set(Calendar.YEAR, year);
mCalendar.set(Calendar.MONTH, month);
mCalendar.set(Calendar.DAY_OF_MONTH, day);
String title = DateUtils.formatDateTime(mContext,
mCalendar.getTimeInMillis(),
DateUtils.FORMAT_SHOW_DATE
| DateUtils.FORMAT_SHOW_WEEKDAY
| DateUtils.FORMAT_SHOW_YEAR
| DateUtils.FORMAT_ABBREV_MONTH
| DateUtils.FORMAT_ABBREV_WEEKDAY);
setTitle(title);
mTitleNeedsUpdate = true;
} else {
if (mTitleNeedsUpdate) {
mTitleNeedsUpdate = false;
setTitle(R.string.date_picker_dialog_title);
}
}
|
|