# Titanium.UI.Picker

A control used to select one or more fixed values.

Availability
0.8
0.8
9.2.0

# Overview

Android iOS Windows
Android iOS Windows

Use the Titanium.UI.createPicker method or Alloy <Picker> element to create a picker control.

On Android, the useSpinner property must be enabled to support multiple columns. By default, the spinner is automatically sized to fit its content and can overflow to additional spinner rows. The size of the picker can be adjusted with the width and height properties, but may omit picker columns or cut off picker rows if the size is set too small. This property is deprecated. Please use the default Android native "dropdown" style by not setting useSpinner to true.

On iOS, the height property is only available in iOS 9 and later. By default, the size of the picker, including its background, is fixed at the same height as the iPhone keyboard to respect the iOS Human Interface Guidelines (opens new window). The default width on iOS is 320px and the height is 228px. The contents of the picker are sized to fit the picker, which may cut off text in the picker rows. Adding views to picker rows is also supported on iOS.

On iPad, Apple recommends using a picker only in a popover. Since the size of the picker cannot be adjusted, it is not suitable for the main screen.

Note: you can only set the Titanium.UI.Picker.columns property for the plain picker. If you set the Titanium.UI.Picker.type property to anything else except Titanium.UI.PICKER_TYPE_PLAIN, you cannot modify the picker's columns.

# Examples

# Multi-Column Picker using Alloy XML Markup

Creates a picker with two columns. You can optionally use Column and Row as shorthand notation for PickerColumn and PickerRow, respectively.

app/views/index.xml:

<Alloy>
    <Window id="win" backgroundColor="white" layout="vertical" exitOnClose="true">
        <Picker id="picker" top="50" selectionIndicator="true" useSpinner="true">
            <PickerColumn id="column1">
                <PickerRow title="Bananas"/>
                <PickerRow title="Strawberries"/>
                <PickerRow title="Mangos"/>
                <PickerRow title="Grapes"/>
            </PickerColumn>
            <!-- Picker shorthand notation -->
            <Column id="column2">
                <Row title="red"/>
                <Row title="green"/>
                <Row title="blue"/>
                <Row title="orange"/>
            </Column>
        </Picker>
    </Window>
</Alloy>

app/controllers/index.js:

$.win.open();

# Date Picker using Alloy XML Markup

Creates a date picker, then monitors the change event to see when the user updates the picker.

For the date string, use string values accepted by the moment.js constructor in the XML and TSS files. If you are defining dates in the controller code, use a JavaScript Date object.

app/views/index.xml:

<Alloy>
    <Window backgroundColor="blue">
        <Picker id="picker"
          onChange="report"
          type="Ti.UI.PICKER_TYPE_DATE"
          minDate="2014,4,1"
          maxDate="May 1, 2014 12:00:00"
          value="2014-04-15T12:00:00">
        </Picker>
    </Window>
</Alloy>

app/controllers/index.js:

function report(e) {
    Ti.API.info('User selected: ' + e.value);
}

$.index.open();

# Basic Single Column Picker

Create a one-column, platform-specific style, picker and automatically select a row.

Ti.UI.backgroundColor = 'white';
var win = Ti.UI.createWindow({
  exitOnClose: true,
  layout: 'vertical'
});

var picker = Ti.UI.createPicker({
  top:50
});

var data = [];
data[0]=Ti.UI.createPickerRow({title:'Bananas'});
data[1]=Ti.UI.createPickerRow({title:'Strawberries'});
data[2]=Ti.UI.createPickerRow({title:'Mangos'});
data[3]=Ti.UI.createPickerRow({title:'Grapes'});

picker.add(data);
picker.selectionIndicator = true;

win.add(picker);
win.open();

// must be after picker has been displayed
picker.setSelectedRow(0, 2, false); // select Mangos

# Multi-Column Picker

Create a two-column, platform-specific style, picker and automatically select a row in each column.

Ti.UI.backgroundColor = 'white';
var win = Ti.UI.createWindow({
  exitOnClose: true,
  layout: 'vertical'
});

var picker = Ti.UI.createPicker({
  top:50,
  useSpinner: true
});
picker.selectionIndicator = true;

var fruit = [ 'Bananas', 'Strawberries', 'Mangos', 'Grapes' ];
var color = [ 'red', 'green', 'blue', 'orange' ];

var column1 = Ti.UI.createPickerColumn();

for(var i=0, ilen=fruit.length; i<ilen; i++){
  var row = Ti.UI.createPickerRow({
    title: fruit[i]
  });
  column1.addRow(row);
}

var column2 = Ti.UI.createPickerColumn();

for(var i=0, ilen=color.length; i<ilen; i++){
  var row = Ti.UI.createPickerRow({ title: color[i] });
  column2.addRow(row);
}

picker.add([column1,column2]);

win.add(picker);

win.open();

// must be after picker has been displayed
picker.setSelectedRow(0, 2, false); // select Mangos
picker.setSelectedRow(1, 3, false); // select Orange

# Date Picker

Create a date picker and handle the subsequent user action.

Ti.UI.backgroundColor = 'white';
var win = Ti.UI.createWindow({
  exitOnClose: true,
  layout: 'vertical'
});

var picker = Ti.UI.createPicker({
  type:Ti.UI.PICKER_TYPE_DATE,
  minDate:new Date(2009,0,1),
  maxDate:new Date(2014,11,31),
  value:new Date(2014,3,12),
  top:50
});

win.add(picker);
win.open();

picker.addEventListener('change',function(e){
  Ti.API.info("User selected date: " + e.value.toLocaleString());
});

# Date Picker using showDatePickerDialog() (Android only)

Create a date picker that is automatically displayed as a modal dialog and handle the subsequent user action.

Ti.UI.backgroundColor = 'white';

var picker = Ti.UI.createPicker({
  type:Ti.UI.PICKER_TYPE_DATE,
  minDate:new Date(2009,0,1),
  maxDate:new Date(2014,11,31),
  value:new Date(2014,3,12)
});

picker.showDatePickerDialog({
  value: new Date(2010,8,1),
  callback: function(e) {
    if (e.cancel) {
      Ti.API.info('User canceled dialog');
    } else {
      Ti.API.info('User selected date: ' + e.value);
    }
  }
});

# Properties

# backgroundColor

Availability
0.9.0
5.2.0
9.2.0
backgroundColor :String | Titanium.UI.Color

Background color of the picker, as a color name or hex triplet.

For information about color values, see the "Colors" section of Titanium.UI.

Default: White (iOS), Transparent (Android)


# borderStyle CREATION ONLY

Availability
10.0.1
borderStyle :Number

Border style to use when picker is shown as a text field or drop-down field.

This is an Android only property which only applies to pickers of type:

Default: Titanium.UI.INPUT_BORDERSTYLE_FILLED


# calendarViewShown

Availability
0.8
calendarViewShown :Boolean

Determines whether the calenderView is visible.

If 'calendarViewShown' is 'true', the calenderView is visible

Default: false


# columns

Availability
0.8
0.8
9.2.0
columns :Array<Titanium.UI.PickerColumn>

Columns used for this picker, as an array of Titanium.UI.PickerColumn objects.

You can only set columns for the plain picker. If you set the type to anything else except Titanium.UI.PICKER_TYPE_PLAIN, you cannot modify the columns.

In an Alloy application you can specify this property with a <PickerColumn> (or <Column>) element that contains one or more <PickerRow> (or <Row>) elements, as shown below:

<Alloy>
    <Window>
        <Picker useSpinner="true">
            <PickerColumn id="column1">
                <PickerRow title="Bananas"/>
                <PickerRow title="Strawberries"/>
                <PickerRow title="Mangos"/>
            </PickerColumn>
            <!-- Picker shorthand notation -->
            <Column id="column2">
                <Row title="red"/>
                <Row title="green"/>
                <Row title="blue"/>
            </Column>
        </Picker>
    </Window>
</Alloy>

# countDownDuration

Availability
0.8
9.2.0
countDownDuration :Number

Duration in milliseconds used for a Countdown Timer picker.

Applicable to PICKER_TYPE_COUNT_DOWN_TIMER picker types.


# datePickerStyle CREATION ONLY

Availability
10.0.1
9.2.0
9.2.0
datePickerStyle :Number

Determines how a date or time picker should appear.

Used to display the picker has calendar/clock view, as wheel spinners, or as a field which displays selection dialog when tapped on.

This property is ignored if the type property is set to PICKER_TYPE_PLAIN.

Default: Titanium.UI.DATE_PICKER_STYLE_AUTOMATIC


# dateTimeColor

Availability
5.2.0
dateTimeColor :String | Titanium.UI.Color

Sets the text color of date- and time-pickers.

Applicable to PICKER_TYPE_TIME and PICKER_TYPE_DATE_AND_TIME picker types. The picker type PICKER_TYPE_DATE does not support text customizing as stated in the UIKit User Interface Catalog.

Important: On iOS 14+, you also have to set the datePickerStyle to DATE_PICKER_STYLE_WHEELS in order to use this property.

Default: black


# font

Availability
0.8
font :Font

Font to use for text.

Only applicable to PICKER_TYPE_DATE and PICKER_TYPE_TIME picker types for android. For PICKER_TYPE_PLAIN, refer to Titanium.UI.PickerColumn for android, and Titanium.UI.PickerRow for iphone / ipad.


# format24

Availability
0.8
format24 :Boolean

Determines whether the Time pickers display in 24-hour or 12-hour clock format.

Only applcable to pickers of type PICKER_TYPE_TIME.

When this property is set true, a time picker is displayed with hours 0 through 23. When set false, hours will be 1 through 12 with am/pm controls.

Default: false


# hintText

Availability
10.0.1
hintText :String

Text to be shown above date/time when picker is shown as a text field or drop-down field.

This is an Android only property which only applies to pickers of type:

Default: undefined


# locale

Availability
0.8
locale :String

Locale used when displaying Date and Time picker values.

Applicable to PICKER_TYPE_DATE, PICKER_TYPE_TIME and PICKER_TYPE_DATE_AND_TIME picker types.

Locale must be represented as a combination of ISO 2-letter language and country codes. For example, en-US or en-GB. See the ISO 639-1 and ISO 3166-1 alpha-2 sections of wikipedia for reference.

On iOS, the system locale is always used.

Default: System Settings


# maxDate

Availability
0.8
0.8
9.2.0
maxDate :Date

Maximum date displayed when a Date picker is in use.

Applicable to PICKER_TYPE_DATE and PICKER_TYPE_DATE_AND_TIME picker types.

For JavaScript files, use a JavaScript Date object.

For Alloy XML and TSS files, use a date string that can be parsed by the moment.js constructor, which includes ISO-8601 and RFC2822 dates.

This property is ignored when maxDate is less than minDate.


# minDate

Availability
0.8
0.8
9.2.0
minDate :Date

Minimum date displayed when a Date picker is in use.

Applicable to PICKER_TYPE_DATE and PICKER_TYPE_DATE_AND_TIME picker types.

For JavaScript files, use a JavaScript Date object.

For Alloy XML and TSS files, use a date string that can be parsed by the moment.js constructor, which includes ISO-8601 and RFC2822 dates.

This property is ignored when maxDate is less than minDate.


# minuteInterval

Availability
0.8
9.2.0
minuteInterval :Number

Interval in minutes displayed when one of the Time types of pickers is in use.

Applicable to PICKER_TYPE_TIME and PICKER_TYPE_DATE_AND_TIME picker types.

The minimum permitted value is 1 and maximum is 30. If the value cannot be evenly divided into 60, the default value is used.

Default: 1


# nativeSpinner CREATION ONLY

Availability
5.4.0
nativeSpinner :Boolean

Determines if a multicolumn spinner or single column drop-down picker should be used.

This property is intended to be used by time picker types.

If true, Android will show hour, minute, and am/pm spinners like iOS.

If false, Android will display a clock view.

If undefined with Titanium 10.0.1 or higher, the datePickerStyle property is used.

As of Titanium 10.0.1, this property has the same effect as the useSpinner property which also shows a native spinner.

const picker = Ti.UI.createPicker({
    type: Ti.UI.PICKER_TYPE_TIME,
    nativeSpinner: true,
    format24: false,
    minuteInterval: 4,
    minDate: new Date(2018, 5, 24),
    maxDate: new Date(2020, 5, 24),
    value: new Date(2019, 5, 24)
});

Default: false


# selectionIndicator DEPRECATED

Availability
0.8
selectionIndicator :Boolean

DEPRECATED SINCE 10.0.1

This property is ignored as of Titanium 10.0.1.

Determines whether the visual selection indicator is shown.

As of Titanium 10.0.1, this property will be ignored and Android will always show an indicator.

Default: true


# selectionOpens

Availability
5.0.0
selectionOpens :Boolean

Determines whether calling the method setSelectedRow opens when called

If true, selection will open when setSelectedRow is called.

If false, selection will not open when setSelectedRow is called.

Default: false (Android)


# type

Availability
0.8
0.8
9.2.0
type :Number

Determines the type of picker displayed

You can only set columns for the plain picker. If you set the type to anything else except Titanium.UI.PICKER_TYPE_PLAIN, you cannot modify the columns.

PICKER_TYPE_DATE_AND_TIME is only available for iOS. PICKER_TYPE_COUNT_DOWN_TIMER is only available for iOS.

Default: Titanium.UI.PICKER_TYPE_PLAIN


# useSpinner CREATION ONLY

Availability
0.8
useSpinner :Boolean

Determines if a multicolumn spinner or single column drop-down picker should be used.

This property is intended to be used by plain picker types. When set on date/time pickers, this property will override the datePickerStyle property.

If true, Android will show spinners for each column like iOS.

If false, Android will display the 1st column as a drop-down list picker and all other columns will be ignored.

As of Titanium 10.0.1, this property shows a native Android spinner widget like how the nativeSpinner property worked in older versions. On older Titanium versions, this property shows a non-native custom spinner view.

Default: false


# value

Availability
0.8
0.8
9.2.0
value :Date

Date and time value for Date and Time pickers.

Applicable to PICKER_TYPE_DATE, PICKER_TYPE_TIME and PICKER_TYPE_DATE_AND_TIME picker types.

For JavaScript files, use a JavaScript Date object.

For Alloy XML and TSS files, use a date string that can be parsed by the moment.js constructor, which includes ISO-8601 and RFC2822 dates.


# visibleItems DEPRECATED

Availability
0.8
visibleItems :Number

DEPRECATED SINCE 10.0.1

This property is ignored as of Titanium 10.0.1.

Number of visible rows to display. This is only applicable to a plain picker and when the useSpinner is true.

The spinner-style Android picker shows 5 rows by default; one selected in the middle and 2 above and below. Set to an odd number to ensure the selected row is in the middle.

Default: 5

# Methods

# add

Availability
0.9
0.9
9.2.0
add(data) void

Adds rows or columns to the picker.

Once you use this method to add rows and columns to a picker, you cannot remove or manipulate them.

Parameters

Name Type Description
data Array<Titanium.UI.PickerRow> | Titanium.UI.PickerRow | Array<Titanium.UI.PickerColumn> | Titanium.UI.PickerColumn

A row, set of rows, a column of rows or a set of columns of rows. When this method is used to add a row or set of rows, a single-column picker is created.

Returns

Type
void

# getSelectedRow

Availability
0.8
0.8
9.2.0
getSelectedRow(index) Titanium.UI.PickerRow

Gets the selected row for a column, or null if none exists.

Parameters

Name Type Description
index Number

A column index.

Returns


# reloadColumn

Availability
0.8
9.2.0
reloadColumn(column) void

Repopulates values for a column.

Parameters

Name Type Description
column Titanium.UI.PickerColumn

Column to repopulate.

Returns

Type
void

# setSelectedRow

Availability
0.8
0.8
9.2.0
setSelectedRow(column, row[, animated]) void

Selects a column's row.

On iOS, this method must be called after the picker is rendered. On Android, the picker has a default value of 0 for both column and row index.

Parameters

Name Type Description
column Number

A column index.

row Number

A row index.

animated Boolean

Determines whether the selection should be animated. (iPhone, iPad-only)

Returns

Type
void

# setValue DEPRECATED

Availability
0.8
9.2.0
setValue(date) Titanium.UI.PickerRow

DEPRECATED SINCE 10.0.0

Use the <Titanium.Picker.value> property instead

Sets the date and time value property for Date pickers.

Applicable to the PICKER_TYPE_DATE and PICKER_TYPE_DATE_AND_TIME picker types.

Parameters

Name Type Description
date Date

A Javascript Date object.

Returns


# showDatePickerDialog

Availability
0.8
showDatePickerDialog(dictObj) void

Shows Date picker as a modal dialog.

Applicable to the PICKER_TYPE_DATE picker type.

See "Date Picker using showDatePickerDialog()" for an example.

Parameters

Name Type Description
dictObj Object

Dictionary object with a subset of Titanium.UI.Picker properties and a callback defined. Acceptable object properties are callback, title and value. Property okButtonTitle is only supported on Titanium versions older than 10.0.0.

Returns

Type
void

# showTimePickerDialog

Availability
0.8
showTimePickerDialog(dictObj) void

Shows Time picker as a modal dialog.

Applicable to the PICKER_TYPE_TIME picker type.

See "Date Picker using showDatePickerDialog()" for a similar example.

Parameters

Name Type Description
dictObj Object

Dictionary object with a subset of Titanium.UI.Picker properties and a callback defined. Acceptable object properties are callback, format24, title and value. Property okButtonTitle is only supported on Titanium versions older than 10.0.0.

Returns

Type
void

# Events

# click

Availability
3.0.0

Fired when the device detects a click against the view.

This event is only available for non-spinner plain pickers.

Properties

Name Type Description
x Number

X coordinate of the event from the source view's coordinate system.

y Number

Y coordinate of the event from the source view's coordinate system.

source Object

Source object that fired the event.

type String

Name of the event fired.

bubbles Boolean

True if the event will try to bubble up if possible.

cancelBubble Boolean

Set to true to stop the event from bubbling.


# change

Availability
0.8
0.8
9.2.0

Fired when the value of any column's row is changed.

Properties

Name Type Description
columnIndex Number

Selected column index. On iOS, only applicable to PICKER_TYPE_PLAIN picker types.

rowIndex Number

Selected row index. On iOS, only applicable to PICKER_TYPE_PLAIN picker types.

column Titanium.UI.PickerColumn

The column object. On iOS, only applicable to PICKER_TYPE_PLAIN picker types.

countDownDuration Number

The selected duration in milliseconds. Applicable to PICKER_TYPE_COUNT_DOWN_TIMER picker types.

value String

The selected value. Applicable to date/time pickers only. This property is read-only on Android.

row Titanium.UI.PickerRow

The row object. On iOS, only applicable to PICKER_TYPE_PLAIN picker types.

selectedValue Array<String>

Array of selected values, one element per column in the picker. Applicable to PICKER_TYPE_PLAIN picker types.

source Object

Source object that fired the event.

type String

Name of the event fired.

bubbles Boolean

True if the event will try to bubble up if possible.

cancelBubble Boolean

Set to true to stop the event from bubbling.