public class

CalendarView

extends FrameLayout
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ android.widget.CalendarView

Class Overview

This class is a calendar widget for displaying and selecting dates. The range of dates supported by this calendar is configurable. A user can select a date by taping on it and can scroll and fling the calendar to a desired date.

Summary

Nested Classes
interface CalendarView.OnDateChangeListener The callback used to indicate the user changes the date. 
XML Attributes
Attribute Name Related Method Description
android:dateTextAppearance The text appearance for the calendar dates. 
android:firstDayOfWeek The first day of week according to Calendar
android:focusedMonthDateColor The color for the dates of the selected month. 
android:maxDate The minimal date shown by this calendar view in mm/dd/yyyy format. 
android:minDate The minimal date shown by this calendar view in mm/dd/yyyy format. 
android:selectedDateVerticalBar Drawable for the vertical bar shown at the beggining and at the end of a selected date. 
android:selectedWeekBackgroundColor The background color for the selected week. 
android:showWeekNumber Whether do show week numbers. 
android:shownWeekCount The number of weeks to be shown. 
android:unfocusedMonthDateColor The color for the dates of an unfocused month. 
android:weekDayTextAppearance The text appearance for the week day abbreviation of the calendar header. 
android:weekNumberColor The color for the week numbers. 
android:weekSeparatorLineColor The color for the sepatator line between weeks. 
[Expand]
Inherited XML Attributes
From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
CalendarView(Context context)
CalendarView(Context context, AttributeSet attrs)
CalendarView(Context context, AttributeSet attrs, int defStyle)
Public Methods
long getDate()
Gets the selected date in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.
int getFirstDayOfWeek()
Gets the first day of week.
long getMaxDate()
Gets the maximal date supported by this CalendarView in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.
long getMinDate()
Gets the minimal date supported by this CalendarView in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.
boolean getShowWeekNumber()
Gets whether to show the week number.
boolean isEnabled()
Returns the enabled status for this view.
void setDate(long date, boolean animate, boolean center)
Sets the selected date in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.
void setDate(long date)
Sets the selected date in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.
void setEnabled(boolean enabled)
Set the enabled state of this view.
void setFirstDayOfWeek(int firstDayOfWeek)
Sets the first day of week.
void setMaxDate(long maxDate)
Sets the maximal date supported by this CalendarView in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.
void setMinDate(long minDate)
Sets the minimal date supported by this CalendarView in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.
void setOnDateChangeListener(CalendarView.OnDateChangeListener listener)
Sets the listener to be notified upon selected date change.
void setShowWeekNumber(boolean showWeekNumber)
Sets whether to show the week number.
Protected Methods
void onConfigurationChanged(Configuration newConfig)
Called when the current configuration of the resources being used by the application have changed.
[Expand]
Inherited Methods
From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource

XML Attributes

android:dateTextAppearance

The text appearance for the calendar dates.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol dateTextAppearance.

Related Methods

android:firstDayOfWeek

The first day of week according to Calendar.

Must be an integer value, such as "100".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol firstDayOfWeek.

Related Methods

android:focusedMonthDateColor

The color for the dates of the selected month.

May be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

This corresponds to the global attribute resource symbol focusedMonthDateColor.

Related Methods

android:maxDate

The minimal date shown by this calendar view in mm/dd/yyyy format.

Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol maxDate.

Related Methods

android:minDate

The minimal date shown by this calendar view in mm/dd/yyyy format.

Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol minDate.

Related Methods

android:selectedDateVerticalBar

Drawable for the vertical bar shown at the beggining and at the end of a selected date.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol selectedDateVerticalBar.

Related Methods

android:selectedWeekBackgroundColor

The background color for the selected week.

May be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

This corresponds to the global attribute resource symbol selectedWeekBackgroundColor.

Related Methods

android:showWeekNumber

Whether do show week numbers.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol showWeekNumber.

Related Methods

android:shownWeekCount

The number of weeks to be shown.

Must be an integer value, such as "100".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol shownWeekCount.

Related Methods

android:unfocusedMonthDateColor

The color for the dates of an unfocused month.

May be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

This corresponds to the global attribute resource symbol unfocusedMonthDateColor.

Related Methods

android:weekDayTextAppearance

The text appearance for the week day abbreviation of the calendar header.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol weekDayTextAppearance.

Related Methods

android:weekNumberColor

The color for the week numbers.

May be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

This corresponds to the global attribute resource symbol weekNumberColor.

Related Methods

android:weekSeparatorLineColor

The color for the sepatator line between weeks.

May be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

This corresponds to the global attribute resource symbol weekSeparatorLineColor.

Related Methods

Public Constructors

public CalendarView (Context context)

Since: API Level 11

public CalendarView (Context context, AttributeSet attrs)

Since: API Level 11

public CalendarView (Context context, AttributeSet attrs, int defStyle)

Since: API Level 11

Public Methods

public long getDate ()

Since: API Level 11

Gets the selected date in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.

Returns
  • The selected date.

public int getFirstDayOfWeek ()

Since: API Level 11

Gets the first day of week.

Returns
  • The first day of the week conforming to the CalendarView APIs.

public long getMaxDate ()

Since: API Level 11

Gets the maximal date supported by this CalendarView in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.

Note: The default maximal date is 01/01/2100.

Returns
  • The maximal supported date.

public long getMinDate ()

Since: API Level 11

Gets the minimal date supported by this CalendarView in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.

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

Returns
  • The minimal supported date.

public boolean getShowWeekNumber ()

Since: API Level 11

Gets whether to show the week number.

Returns
  • True if showing the week number.

public boolean isEnabled ()

Since: API Level 11

Returns the enabled status for this view. The interpretation of the enabled state varies by subclass.

Returns
  • True if this view is enabled, false otherwise.

public void setDate (long date, boolean animate, boolean center)

Since: API Level 11

Sets the selected date in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.

Parameters
date The date.
animate Whether to animate the scroll to the current date.
center Whether to center the current date even if it is already visible.
Throws
IllegalArgumentException of the provided date is before the minimal or after the maximal date.

public void setDate (long date)

Since: API Level 11

Sets the selected date in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.

Parameters
date The selected date.
Throws
IllegalArgumentException of the provided date is before the minimal or after the maximal date.

public void setEnabled (boolean enabled)

Since: API Level 11

Set the enabled state of this view. The interpretation of the enabled state varies by subclass.

Parameters
enabled True if this view is enabled, false otherwise.

public void setFirstDayOfWeek (int firstDayOfWeek)

Since: API Level 11

Sets the first day of week.

Parameters
firstDayOfWeek The first day of the week conforming to the CalendarView APIs.

public void setMaxDate (long maxDate)

Since: API Level 11

Sets the maximal date supported by this CalendarView in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.

Parameters
maxDate The maximal supported date.

public void setMinDate (long minDate)

Since: API Level 11

Sets the minimal date supported by this CalendarView in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.

Parameters
minDate The minimal supported date.

public void setOnDateChangeListener (CalendarView.OnDateChangeListener listener)

Since: API Level 11

Sets the listener to be notified upon selected date change.

Parameters
listener The listener to be notified.

public void setShowWeekNumber (boolean showWeekNumber)

Since: API Level 11

Sets whether to show the week number.

Parameters
showWeekNumber True to show the week number.

Protected Methods

protected void onConfigurationChanged (Configuration newConfig)

Since: API Level 11

Called when the current configuration of the resources being used by the application have changed. You can use this to decide when to reload resources that can changed based on orientation and other configuration characterstics. You only need to use this if you are not relying on the normal Activity mechanism of recreating the activity instance upon a configuration change.

Parameters
newConfig The new resource configuration.