FileDocCategorySizeDatePackage
DatePicker.javaAPI DocAndroid 5.1 API44326Thu Mar 12 22:22:10 GMT 2015android.widget

DatePicker

public class DatePicker extends FrameLayout
Provides a widget for selecting a date.

When the {@link android.R.styleable#DatePicker_datePickerMode} attribute is set to {@code spinner}, the date can be selected using year, month, and day spinners or a {@link CalendarView}. The set of spinners and the calendar view are automatically synchronized. The client can customize whether only the spinners, or only the calendar view, or both to be displayed.

When the {@link android.R.styleable#DatePicker_datePickerMode} attribute is set to {@code calendar}, the month and day can be selected using a calendar-style view while the year can be selected separately using a list.

See the Pickers guide.

For a dialog using this view, see {@link android.app.DatePickerDialog}.

attr
ref android.R.styleable#DatePicker_startYear
attr
ref android.R.styleable#DatePicker_endYear
attr
ref android.R.styleable#DatePicker_maxDate
attr
ref android.R.styleable#DatePicker_minDate
attr
ref android.R.styleable#DatePicker_spinnersShown
attr
ref android.R.styleable#DatePicker_calendarViewShown
attr
ref android.R.styleable#DatePicker_dayOfWeekBackground
attr
ref android.R.styleable#DatePicker_dayOfWeekTextAppearance
attr
ref android.R.styleable#DatePicker_headerBackground
attr
ref android.R.styleable#DatePicker_headerMonthTextAppearance
attr
ref android.R.styleable#DatePicker_headerDayOfMonthTextAppearance
attr
ref android.R.styleable#DatePicker_headerYearTextAppearance
attr
ref android.R.styleable#DatePicker_yearListItemTextAppearance
attr
ref android.R.styleable#DatePicker_yearListSelectorColor
attr
ref android.R.styleable#DatePicker_calendarTextColor
attr
ref android.R.styleable#DatePicker_datePickerMode

Fields Summary
private static final String
LOG_TAG
private static final int
MODE_SPINNER
private static final int
MODE_CALENDAR
private final DatePickerDelegate
mDelegate
Constructors Summary
public DatePicker(android.content.Context context)


                   
       

                                                                       
                
    

       
        this(context, null);
    
public DatePicker(android.content.Context context, android.util.AttributeSet attrs)

        this(context, attrs, R.attr.datePickerStyle);
    
public DatePicker(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr)

        this(context, attrs, defStyleAttr, 0);
    
public DatePicker(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr, int defStyleRes)

        super(context, attrs, defStyleAttr, defStyleRes);

        final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DatePicker,
                defStyleAttr, defStyleRes);
        final int mode = a.getInt(R.styleable.DatePicker_datePickerMode, MODE_SPINNER);
        final int firstDayOfWeek = a.getInt(R.styleable.DatePicker_firstDayOfWeek, 0);
        a.recycle();

        switch (mode) {
            case MODE_CALENDAR:
                mDelegate = createCalendarUIDelegate(context, attrs, defStyleAttr, defStyleRes);
                break;
            case MODE_SPINNER:
            default:
                mDelegate = createSpinnerUIDelegate(context, attrs, defStyleAttr, defStyleRes);
                break;
        }

        if (firstDayOfWeek != 0) {
            setFirstDayOfWeek(firstDayOfWeek);
        }
    
Methods Summary
private android.widget.DatePicker$DatePickerDelegatecreateCalendarUIDelegate(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr, int defStyleRes)

        return new DatePickerCalendarDelegate(this, context, attrs, defStyleAttr,
                defStyleRes);
    
private android.widget.DatePicker$DatePickerDelegatecreateSpinnerUIDelegate(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr, int defStyleRes)

        return new DatePickerSpinnerDelegate(this, context, attrs, defStyleAttr, defStyleRes);
    
public booleandispatchPopulateAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)

        return mDelegate.dispatchPopulateAccessibilityEvent(event);
    
protected voiddispatchRestoreInstanceState(android.util.SparseArray container)

        dispatchThawSelfOnly(container);
    
public CalendarViewgetCalendarView()
Gets the {@link CalendarView}.

This method returns {@code null} when the {@link android.R.styleable#DatePicker_datePickerMode} attribute is set to {@code calendar}.

return
The calendar view.
see
#getCalendarViewShown()

        return mDelegate.getCalendarView();
    
public booleangetCalendarViewShown()
Gets whether the {@link CalendarView} is shown.

return
True if the calendar view is shown.
see
#getCalendarView()

        return mDelegate.getCalendarViewShown();
    
public intgetDayOfMonth()

return
The selected day of month.

        return mDelegate.getDayOfMonth();
    
public intgetFirstDayOfWeek()
Gets the first day of week.

return
The first day of the week conforming to the {@link CalendarView} APIs.
see
Calendar#SUNDAY
see
Calendar#MONDAY
see
Calendar#TUESDAY
see
Calendar#WEDNESDAY
see
Calendar#THURSDAY
see
Calendar#FRIDAY
see
Calendar#SATURDAY
attr
ref android.R.styleable#DatePicker_firstDayOfWeek

        return mDelegate.getFirstDayOfWeek();
    
public longgetMaxDate()
Gets the maximal date supported by this {@link DatePicker} in milliseconds since January 1, 1970 00:00:00 in {@link TimeZone#getDefault()} time zone.

Note: The default maximal date is 12/31/2100.

return
The maximal supported date.

        return mDelegate.getMaxDate().getTimeInMillis();
    
public longgetMinDate()
Gets the minimal date supported by this {@link DatePicker} in milliseconds since January 1, 1970 00:00:00 in {@link TimeZone#getDefault()} time zone.

Note: The default minimal date is 01/01/1900.

return
The minimal supported date.

        return mDelegate.getMinDate().getTimeInMillis();
    
public intgetMonth()

return
The selected month.

        return mDelegate.getMonth();
    
public booleangetSpinnersShown()
Gets whether the spinners are shown.

return
True if the spinners are shown.

        return mDelegate.getSpinnersShown();
    
public intgetYear()

return
The selected year.

        return mDelegate.getYear();
    
public voidinit(int year, int monthOfYear, int dayOfMonth, android.widget.DatePicker$OnDateChangedListener onDateChangedListener)
Initialize the state. If the provided values designate an inconsistent date the values are normalized before updating the spinners.

param
year The initial year.
param
monthOfYear The initial month starting from zero.
param
dayOfMonth The initial day of the month.
param
onDateChangedListener How user is notified date is changed by user, can be null.

        mDelegate.init(year, monthOfYear, dayOfMonth, onDateChangedListener);
    
public booleanisEnabled()

        return mDelegate.isEnabled();
    
protected voidonConfigurationChanged(android.content.res.Configuration newConfig)

        super.onConfigurationChanged(newConfig);
        mDelegate.onConfigurationChanged(newConfig);
    
public voidonInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)

        super.onInitializeAccessibilityEvent(event);
        mDelegate.onInitializeAccessibilityEvent(event);
    
public voidonInitializeAccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo info)

        super.onInitializeAccessibilityNodeInfo(info);
        mDelegate.onInitializeAccessibilityNodeInfo(info);
    
public voidonPopulateAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)

        super.onPopulateAccessibilityEvent(event);
        mDelegate.onPopulateAccessibilityEvent(event);
    
protected voidonRestoreInstanceState(android.os.Parcelable state)

        BaseSavedState ss = (BaseSavedState) state;
        super.onRestoreInstanceState(ss.getSuperState());
        mDelegate.onRestoreInstanceState(ss);
    
protected android.os.ParcelableonSaveInstanceState()

        Parcelable superState = super.onSaveInstanceState();
        return mDelegate.onSaveInstanceState(superState);
    
public voidsetCalendarViewShown(boolean shown)
Sets whether the {@link CalendarView} is shown.

Calling this method has no effect when the {@link android.R.styleable#DatePicker_datePickerMode} attribute is set to {@code calendar}.

param
shown True if the calendar view is to be shown.

        mDelegate.setCalendarViewShown(shown);
    
public voidsetEnabled(boolean enabled)

        if (mDelegate.isEnabled() == enabled) {
            return;
        }
        super.setEnabled(enabled);
        mDelegate.setEnabled(enabled);
    
public voidsetFirstDayOfWeek(int firstDayOfWeek)
Sets the first day of week.

param
firstDayOfWeek The first day of the week conforming to the {@link CalendarView} APIs.
see
Calendar#SUNDAY
see
Calendar#MONDAY
see
Calendar#TUESDAY
see
Calendar#WEDNESDAY
see
Calendar#THURSDAY
see
Calendar#FRIDAY
see
Calendar#SATURDAY
attr
ref android.R.styleable#DatePicker_firstDayOfWeek

        if (firstDayOfWeek < Calendar.SUNDAY || firstDayOfWeek > Calendar.SATURDAY) {
            throw new IllegalArgumentException("firstDayOfWeek must be between 1 and 7");
        }
        mDelegate.setFirstDayOfWeek(firstDayOfWeek);
    
public voidsetMaxDate(long maxDate)
Sets the maximal date supported by this {@link DatePicker} in milliseconds since January 1, 1970 00:00:00 in {@link TimeZone#getDefault()} time zone.

param
maxDate The maximal supported date.

        mDelegate.setMaxDate(maxDate);
    
public voidsetMinDate(long minDate)
Sets the minimal date supported by this {@link NumberPicker} in milliseconds since January 1, 1970 00:00:00 in {@link TimeZone#getDefault()} time zone.

param
minDate The minimal supported date.

        mDelegate.setMinDate(minDate);
    
public voidsetSpinnersShown(boolean shown)
Sets whether the spinners are shown.

param
shown True if the spinners are to be shown.

        mDelegate.setSpinnersShown(shown);
    
public voidsetValidationCallback(android.widget.DatePicker$ValidationCallback callback)
Sets the callback that indicates the current date is valid.

param
callback the callback, may be null
hide

        mDelegate.setValidationCallback(callback);
    
public voidupdateDate(int year, int month, int dayOfMonth)
Update the current date.

param
year The year.
param
month The month which is starting from zero.
param
dayOfMonth The day of the month.

        mDelegate.updateDate(year, month, dayOfMonth);