DatePickerDialogpublic class DatePickerDialog extends AlertDialog implements android.widget.DatePicker.OnDateChangedListener, android.content.DialogInterface.OnClickListenerA simple dialog containing an {@link android.widget.DatePicker}. |
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 | mCallBack | private final Calendar | mCalendar | private final DateFormat | mDateFormat | private final DateFormat | mTitleDateFormat | private final String[] | mWeekDays | private int | mInitialYear | private int | mInitialMonth | private int | mInitialDay |
Constructors Summary |
---|
public DatePickerDialog(android.content.Context context, OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth)
this(context, com.android.internal.R.style.Theme_Dialog_Alert,
callBack, year, monthOfYear, dayOfMonth);
| public DatePickerDialog(android.content.Context context, int theme, OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth)
super(context, theme);
mCallBack = callBack;
mInitialYear = year;
mInitialMonth = monthOfYear;
mInitialDay = dayOfMonth;
DateFormatSymbols symbols = new DateFormatSymbols();
mWeekDays = symbols.getShortWeekdays();
mDateFormat = DateFormat.getMediumDateFormat(context);
mTitleDateFormat = java.text.DateFormat.
getDateInstance(java.text.DateFormat.FULL);
mCalendar = Calendar.getInstance();
updateTitle(mInitialYear, mInitialMonth, mInitialDay);
setButton(context.getText(R.string.date_time_set), this);
setButton2(context.getText(R.string.cancel), (OnClickListener) null);
setIcon(R.drawable.ic_dialog_time);
LayoutInflater inflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.date_picker_dialog, null);
setView(view);
mDatePicker = (DatePicker) view.findViewById(R.id.datePicker);
mDatePicker.init(mInitialYear, mInitialMonth, mInitialDay, this);
|
Methods Summary |
---|
public void | onClick(android.content.DialogInterface dialog, int which)
if (mCallBack != null) {
mDatePicker.clearFocus();
mCallBack.onDateSet(mDatePicker, mDatePicker.getYear(),
mDatePicker.getMonth(), mDatePicker.getDayOfMonth());
}
| public void | onDateChanged(android.widget.DatePicker view, int year, int month, int day)
updateTitle(year, month, day);
| public void | onRestoreInstanceState(android.os.Bundle savedInstanceState)
super.onRestoreInstanceState(savedInstanceState);
int year = savedInstanceState.getInt(YEAR);
int month = savedInstanceState.getInt(MONTH);
int day = savedInstanceState.getInt(DAY);
mDatePicker.init(year, month, day, this);
updateTitle(year, month, day);
| public android.os.Bundle | onSaveInstanceState()
Bundle state = super.onSaveInstanceState();
state.putInt(YEAR, mDatePicker.getYear());
state.putInt(MONTH, mDatePicker.getMonth());
state.putInt(DAY, mDatePicker.getDayOfMonth());
return state;
| public void | show()
super.show();
/* Sometimes the full month is displayed causing the title
* to be very long, in those cases ensure it doesn't wrap to
* 2 lines (as that looks jumpy) and ensure we ellipsize the end.
*/
TextView title = (TextView) findViewById(R.id.alertTitle);
title.setSingleLine();
title.setEllipsize(TruncateAt.END);
| public void | updateDate(int year, int monthOfYear, int dayOfMonth)
mInitialYear = year;
mInitialMonth = monthOfYear;
mInitialDay = dayOfMonth;
mDatePicker.updateDate(year, monthOfYear, dayOfMonth);
| private void | updateTitle(int year, int month, int day)
mCalendar.set(Calendar.YEAR, year);
mCalendar.set(Calendar.MONTH, month);
mCalendar.set(Calendar.DAY_OF_MONTH, day);
setTitle(mTitleDateFormat.format(mCalendar.getTime()));
|
|