Titanium.UI.Picker

Object of Titanium.UI.
Platform Since
Android 0.8
iPhone 0.8
iPad 0.8

Summary

A control used to select one or more fixed values.

Description

Use the Titanium.UI.createPicker method to create a picker control.

On Android, the useSpinner property must be enabled to support multiple columns.

Adding views to picker rows is only supported on iOS.

Code Examples

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
});
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 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)
});
 
win.open();
 
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);
    }
  }
});

Methods

Name Summary
add

Adds rows or columns to the picker. (iPhone, iPad only.)

addEventListener

Adds the specified callback as an event listener for the named event.

fireEvent

Fires a synthesized event to any registered listeners.

getColumns

Gets the value of the columns property.

getCountDownDuration

Gets the value of the countDownDuration property. (iPhone, iPad only.)

getFormat24

Gets the value of the format24 property. (Android only.)

getLocale

Gets the value of the locale property. (Android only.)

getMaxDate

Gets the value of the maxDate property.

getMinDate

Gets the value of the minDate property.

getMinuteInterval

Gets the value of the minuteInterval property. (iPhone, iPad only.)

getSelectedRow

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

getSelectionIndicator

Gets the value of the selectionIndicator property.

getType

Gets the value of the type property.

getUseSpinner

Gets the value of the useSpinner property. (Android only.)

getValue

Gets the value of the value property.

getVisibleItems

Gets the value of the visibleItems property. (Android only.)

reloadColumn

Repopulates values for a column. (iPhone, iPad only.)

removeEventListener

Removes the specified callback as an event listener for the named event.

setColumns

Sets the value of the columns property.

setCountDownDuration

Sets the value of the countDownDuration property. (iPhone, iPad only.)

setFormat24

Sets the value of the format24 property. (Android only.)

setLocale

Sets the value of the locale property. (Android only.)

setMaxDate

Sets the value of the maxDate property.

setMinDate

Sets the value of the minDate property.

setMinuteInterval

Sets the value of the minuteInterval property. (iPhone, iPad only.)

setSelectedRow

Selects a column's row.

setSelectionIndicator

Sets the value of the selectionIndicator property.

setType

Sets the value of the type property.

setUseSpinner

Sets the value of the useSpinner property. (Android only.)

setValue

Sets the date and time value property for Date pickers. (iPhone, iPad only.)

setVisibleItems

Sets the value of the visibleItems property. (Android only.)

showDatePickerDialog

Shows Date picker as a modal dialog. (Android only.)

showTimePickerDialog

Shows Time picker as a modal dialog. (Android only.)

Properties

Name Type Summary
columns Array<Titanium.UI.PickerColumn>

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

countDownDuration Number

Duration in milliseconds used for a Countdown Timer picker. (iPhone, iPad only.)

format24 Boolean

Determines whether the Time pickers display in 24-hour or 12-hour clock format. (Android only.)

locale String

Locale used when displaying Date and Time picker values. (Android only.)

maxDate Date

Maximum date displayed when a Date picker is in use.

minDate Date

Minimum date displayed when a Date picker is in use.

minuteInterval Number

Interval in minutes displayed when one of the Time types of pickers is in use. (iPhone, iPad only.)

selectionIndicator Boolean

Determines whether the visual selection indicator is shown. On iPhone, this is a blue bar.

type Number

Determines the type of picker displayed. One of Titanium.UI.PICKER_TYPE_PLAIN, Titanium.UI.PICKER_TYPE_DATE, Titanium.UI.PICKER_TYPE_TIME, Titanium.UI.PICKER_TYPE_DATE_AND_TIME (iPhone, iPad-only) and Titanium.UI.PICKER_TYPE_COUNT_DOWN_TIMER (iPhone, iPad-only.)

useSpinner Boolean

Determines whether the non-native Android control, with a spinning wheel that looks and behaves like the iOS picker, is invoked rather than the default native "dropdown" style. (Android only.)

value Date

Date and time value for Date pickers.

visibleItems Number

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

Events

Name Summary
change

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