public class

DatePicker

extends View
java.lang.Object
   ↳ com.neomades.ui.View
     ↳ com.neomades.ui.DatePicker

Class Overview

This control lets the user pick a Date.

Day, month and year are available.

Handling Date Changes

 DateChangedListener dateListener = new DateChangedListener() {
 	public void onDateChanged(View source, int day, int month, int year) {
 		// do some stuff
 	}
 };
 DatePicker myDatePicker = new DatePicker();
 myDatePicker.setDateChangedListener(dateListener);
 

Default properties

By default, the following properties are applied to a new DatePicker:

  • focusable (limited to some devices)
  • clickable
  • enabled
  • Selected date (today)
  • no icon
  • width content stretch : MATCH_CONTENT.
  • height content stretch : MATCH_CONTENT.
  • content alignment : HCENTER|VCENTER.
  • mode : MODE_DIALOG_PICKER

Cross Platform Considerations

In Android, the DatePicker has two modes : MODE_INLINE, MODE_DIALOG_PICKER. The MODE_INLINE enables wrapping DatePicker control inside a Layout. The MODE_DIALOG_PICKER mode shows a button with the selected date, when the end-user click him, a dialog is displayed : DatePickerDialog.

Summary

XML Attributes
Attribute Name Related Method Description
contentAlignment setContentAlignment(int) A combination of alignment values (eg: TOP|LEFT)  
day setDay(int) Between 1 and 31  
font setFont(Font) Font resource id: Res.font.FONT_XXXX  
month setMonth(int) 1: JANUARY, 12: DECEMBER  
textColor setTextColor(Color) #AARRGGBB or a color  
textSize setTextSize(int) a size in dp  
year setYear(int)  
[Expand]
Inherited XML Attributes
From class com.neomades.ui.View
Constants
int MODE_DIALOG_PICKER A button is displayed with the value of Date.
int MODE_INLINE Three editors are displayed into the layout in order to input values of Date.
[Expand]
Inherited Constants
From interface com.neomades.ui.Alignment
From interface com.neomades.ui.StretchMode
Public Constructors
DatePicker(int mode)
Constructs a new date picker with the date set to today's day, month and year.
DatePicker()
Constructs a new date picker with the date set to today's day, month and year.
DatePicker(int day, int month, int year)
Constructs a new DatePicker with the date set to the given parameters.
Public Methods
Calendar getCalendar()
Gets the calendar object with the selected date in this picker
Date getDate()
Gets the date object with the selected date in this picker
int getDay()
Returns the day of this DatePicker (always between 1 and 31)
int getMonth()
Returns the month of this DatePicker (always between 1 and 12)
int getYear()
Returns the year of this DatePicker (always between -Infinity and +Infinity)
static void openChooser(View origin, Calendar selectedDate, DateChangedListener listener)
Shows a dialog chooser to the user in order to select a date.
void setContentAlignment(int alignment)
Sets the alignment of the text or icon in the button.
void setDate(Calendar date)
void setDate(Date date)
Sets the date of the DatePicker to the given date Only the day, month and year components will be taken into acount
void setDateChangedListener(DateChangedListener listener)
Sets the listener for this DatePicker, that will be notified if the date changes.
void setDay(int day)
Sets the day number to set (always between 1 and 31)
void setFont(Font font)
Sets the datepicker's button text font.
void setMonth(int month)
Sets the months of this date picker (always between 1 and 12)
void setTextColor(Color textColor)
Sets the DatePicker text color.
void setTextSize(int sizeInDp)
Sets the text size to a given value (in dp).
void setToday()
Sets the date of the DatePicker to today's date
void setYear(int year)
Sets the year of this DatePicker (must be positive)
[Expand]
Inherited Methods
From class com.neomades.ui.View
From class java.lang.Object

XML Attributes

contentAlignment

A combination of alignment values (eg: TOP|LEFT)

Related Methods

day

Between 1 and 31

Related Methods

font

Font resource id: Res.font.FONT_XXXX

Related Methods

month

1: JANUARY, 12: DECEMBER

Related Methods

textColor

#AARRGGBB or a color

Related Methods

textSize

a size in dp

Related Methods

year

Related Methods

Constants

public static final int MODE_DIALOG_PICKER

A button is displayed with the value of Date. When the user clicks on the button, a Dialog is displayed in order to pick a Date.

Default mode for all platforms.

Constant Value: 0 (0x00000000)

public static final int MODE_INLINE

Three editors are displayed into the layout in order to input values of Date. Only available for Android.

In this mode, text customization methods do nothing (text color, text font, text size and text alignment).

Constant Value: 1 (0x00000001)

Public Constructors

public DatePicker (int mode)

Constructs a new date picker with the date set to today's day, month and year.

public DatePicker ()

Constructs a new date picker with the date set to today's day, month and year.

The mode used here is MODE_DIALOG_PICKER.

public DatePicker (int day, int month, int year)

Constructs a new DatePicker with the date set to the given parameters.

Parameters
day the day to set to this date picker. This value must be between 1 and 31.
month the month to set to this date picker. This value must be between 1 and 12.
year the year number

Public Methods

public Calendar getCalendar ()

Gets the calendar object with the selected date in this picker

Returns
  • the selected date

public Date getDate ()

Gets the date object with the selected date in this picker

Returns
  • the selected date
See Also

public int getDay ()

Returns the day of this DatePicker (always between 1 and 31)

Related XML Attributes
Returns
  • the day of this DatePicker (always between 1 and 31)

public int getMonth ()

Returns the month of this DatePicker (always between 1 and 12)

Related XML Attributes
Returns
  • the month of this DatePicker (always between 1 and 12)

public int getYear ()

Returns the year of this DatePicker (always between -Infinity and +Infinity)

Related XML Attributes
Returns
  • the year of this DatePicker (always between -Infinity and +Infinity)

public static void openChooser (View origin, Calendar selectedDate, DateChangedListener listener)

Shows a dialog chooser to the user in order to select a date.

Parameters
origin the view from here the dialog should be opened in iOS.
selectedDate the selected date when the chooser will be shown at the user
listener the callback used to get the selected date or null
Throws
NullPointerException for iOS if the origin parameter is null.

public void setContentAlignment (int alignment)

Sets the alignment of the text or icon in the button. The parameter is a combination of values from Alignment

Only available in MODE_DIALOG_PICKER.

Related XML Attributes
Parameters
alignment The new alignment of the button's text
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void setDate (Calendar date)

See Also

public void setDate (Date date)

Sets the date of the DatePicker to the given date Only the day, month and year components will be taken into acount

Parameters
date the date to set
See Also

public void setDateChangedListener (DateChangedListener listener)

Sets the listener for this DatePicker, that will be notified if the date changes.

Parameters
listener the listener

public void setDay (int day)

Sets the day number to set (always between 1 and 31)

Related XML Attributes
Throws
CrossThreadException if the method is called from outside the UI-Thread
IllegalArgumentException if the day value is not between 1 and 31

public void setFont (Font font)

Sets the datepicker's button text font.

Related XML Attributes
Parameters
font new font for the text
Throws
CrossThreadException if the method is called from outside the UI-Thread
NullPointerException if the font parameter is null

public void setMonth (int month)

Sets the months of this date picker (always between 1 and 12)

Related XML Attributes
Parameters
month the hours to set (always between 1 and 12)
Throws
CrossThreadException if the method is called from outside the UI-Thread
IllegalArgumentException if the month value is not between 1 and 12

public void setTextColor (Color textColor)

Sets the DatePicker text color.

Related XML Attributes
Parameters
textColor new color for the text
Throws
CrossThreadException if the method is called from outside the UI-Thread
NullPointerException if the parameter is null

public void setTextSize (int sizeInDp)

Sets the text size to a given value (in dp).

Related XML Attributes
Parameters
sizeInDp size to set to the text

public void setToday ()

Sets the date of the DatePicker to today's date

public void setYear (int year)

Sets the year of this DatePicker (must be positive)

Related XML Attributes
Parameters
year the years to set
Throws
CrossThreadException if the method is called from outside the UI-Thread
IllegalArgumentException if the year value is negative