/
Picker.yml
724 lines (609 loc) Β· 26.1 KB
/
Picker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
---
name: Titanium.UI.Picker
summary: |
A control used to select one or more fixed values.
description: |
| Android | iOS | Windows |
| ------- | --- | ------- |
| ![Android](./picker_android.png) | ![iOS](./picker_ios.png) | ![Windows](./picker_wp.gif) |
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](https://developer.apple.com/ios/human-interface-guidelines/overview/themes/#//apple_ref/doc/uid/TP40006556-CH15-SW3).
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 [columns](Titanium.UI.Picker.columns) property for the plain picker.
If you set the [type](Titanium.UI.Picker.type) property to anything else except
`Titanium.UI.PICKER_TYPE_PLAIN`, you cannot modify the picker's columns.
extends: Titanium.UI.View
excludes:
properties: [
anchorPoint,backgroundDisabledColor,backgroundDisabledImage,backgroundFocusedColor,children,
backgroundFocusedImage,backgroundGradient,backgroundImage,backgroundLeftCap,backgroundRepeat,
backgroundSelectedColor,backgroundSelectedImage,backgroundTopCap,center,layout,tintColor,zIndex]
methods: [remove, removeAllChildren, replaceAt]
since: "0.8"
platforms: [android, iphone, ipad, macos]
methods:
- name: add
summary: Adds rows or columns to the picker.
description: |
Once you use this method to add rows and columns to a picker, you cannot remove or
manipulate them.
parameters:
- name: data
summary: |
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.
type: [Array<Titanium.UI.PickerRow>, Titanium.UI.PickerRow, Array<Titanium.UI.PickerColumn>, Titanium.UI.PickerColumn]
- name: getSelectedRow
summary: Gets the selected row for a column, or `null` if none exists.
parameters:
- name: index
summary: A column index.
type: Number
returns:
- type: Titanium.UI.PickerRow
- name: reloadColumn
summary: Repopulates values for a column.
parameters:
- name: column
summary: Column to repopulate.
type: Titanium.UI.PickerColumn
platforms: [iphone, ipad, macos]
- name: setSelectedRow
summary: Selects a column's row.
description: |
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: column
summary: A column index.
type: Number
- name: row
summary: A row index.
type: Number
- name: animated
summary: |
Determines whether the selection should be animated. (iPhone, iPad-only)
type: Boolean
default: true
optional: true
- name: setValue
summary: Sets the date and time value property for Date pickers.
description: |
Applicable to the <Titanium.UI.PICKER_TYPE_DATE> and <Titanium.UI.PICKER_TYPE_DATE_AND_TIME>
picker types.
platforms: [iphone, ipad, macos]
parameters:
- name: date
summary: A Javascript `Date` object.
type: Date
returns:
- type: Titanium.UI.PickerRow
deprecated:
since: "10.0.0"
removed: "10.0.0"
notes: Use the <Titanium.Picker.value> property instead
- name: showDatePickerDialog
summary: Shows Date picker as a modal dialog.
description: |
Applicable to the <Titanium.UI.PICKER_TYPE_DATE> picker type.
See "Date Picker using showDatePickerDialog()" for an example.
parameters:
- name: dictObj
summary: |
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.
type: Object
platforms: [android]
- name: showTimePickerDialog
summary: Shows Time picker as a modal dialog.
description: |
Applicable to the <Titanium.UI.PICKER_TYPE_TIME> picker type.
See "Date Picker using showDatePickerDialog()" for a similar example.
parameters:
- name: dictObj
summary: |
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.
type: Object
platforms: [android]
events:
- name: change
summary: Fired when the value of any column's row is changed.
properties:
- name: columnIndex
summary: |
Selected column index. On iOS, only applicable to <Titanium.UI.PICKER_TYPE_PLAIN>
picker types.
type: Number
- name: rowIndex
summary: |
Selected row index. On iOS, only applicable to <Titanium.UI.PICKER_TYPE_PLAIN>
picker types.
type: Number
- name: column
summary: |
The column object. On iOS, only applicable to <Titanium.UI.PICKER_TYPE_PLAIN>
picker types.
type: Titanium.UI.PickerColumn
- name: countDownDuration
summary: |
The selected duration in milliseconds. Applicable to <Titanium.UI.PICKER_TYPE_COUNT_DOWN_TIMER> picker types.
type: Number
- name: value
summary: |
The selected value. Applicable to date/time pickers only. This property is read-only
on Android.
type: String
- name: row
summary: |
The row object. On iOS, only applicable to <Titanium.UI.PICKER_TYPE_PLAIN> picker types.
type: Titanium.UI.PickerRow
- name: selectedValue
summary: |
Array of selected values, one element per column in the picker. Applicable to
<Titanium.UI.PICKER_TYPE_PLAIN> picker types.
type: Array<String>
- name: click
summary: Fired when the device detects a click against the view.
platforms: [android]
since: "3.0.0"
description: |
This event is only available for non-spinner plain pickers.
properties:
- name: x
type: Number
summary: X coordinate of the event from the `source` view's coordinate system.
- name: y
summary: Y coordinate of the event from the `source` view's coordinate system.
type: Number
properties:
- name: backgroundColor
summary: Background color of the picker, as a color name or hex triplet.
description: |
For information about color values, see the "Colors" section of <Titanium.UI>.
Android: If you want to change the backgroundColor you have to set the `borderStyle` to
`Ti.UI.INPUT_BORDERSTYLE_ROUNDED` or `Ti.UI.INPUT_BORDERSTYLE_NONE`
type: [String, Titanium.UI.Color]
platforms: [iphone, ipad, android, macos]
since: { iphone: "5.2.0", ipad: "5.2.0", android: "0.9.0"}
default: White (iOS), Transparent (Android)
- name: borderStyle
summary: Border style to use when picker is shown as a text field or drop-down field.
description: |
This is an Android only property which only applies to pickers of type:
* [PICKER_TYPE_DATE](Titanium.UI.PICKER_TYPE_DATE) or [PICKER_TYPE_TIME](Titanium.UI.PICKER_TYPE_TIME)
that also have [datePickerStyle](Titanium.UI.Picker.datePickerStyle) set to
[DATE_PICKER_STYLE_COMPACT](Titanium.UI.DATE_PICKER_STYLE_COMPACT).
* [PICKER_TYPE_PLAIN](Titanium.UI.PICKER_TYPE_PLAIN) that also have property
[useSpinner](Titanium.UI.Picker.useSpinner) set `false` to show a drop-down picker.
type: Number
constants: Titanium.UI.INPUT_BORDERSTYLE_*
default: <Titanium.UI.INPUT_BORDERSTYLE_FILLED>
availability: creation
platforms: [android]
since: "10.0.1"
- name: columns
summary: Columns used for this picker, as an array of <Titanium.UI.PickerColumn> objects.
description: |
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:
``` xml
<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>
```
type: Array<Titanium.UI.PickerColumn>
- name: countDownDuration
summary: Duration in milliseconds used for a Countdown Timer picker.
description: |
Applicable to <Titanium.UI.PICKER_TYPE_COUNT_DOWN_TIMER> picker types.
type: Number
platforms: [iphone, ipad, macos]
- name: dateTimeColor
summary: Sets the text color of date- and time-pickers.
description: |
Applicable to <Titanium.UI.PICKER_TYPE_TIME> and <Titanium.UI.PICKER_TYPE_DATE_AND_TIME> picker types.
The picker type <Titanium.UI.PICKER_TYPE_DATE> does not support text customizing as stated in the
[UIKit User Interface Catalog](https://developer.apple.com/documentation/uikit/uidatepicker).
Important: On iOS 14+, you also have to set the <Titanium.UI.Picker.datePickerStyle> to
<Titanium.UI.DATE_PICKER_STYLE_WHEELS> in order to use this property.
type: [String, Titanium.UI.Color]
platforms: [iphone, ipad]
since: "5.2.0"
default: "black"
- name: format24
summary: |
Determines whether the Time pickers display in 24-hour or 12-hour clock format.
description: |
Only applcable to pickers of type <Titanium.UI.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.
type: Boolean
default: false
platforms: [android]
- name: hintText
summary: Text to be shown above date/time when picker is shown as a text field or drop-down field.
description: |
This is an Android only property which only applies to pickers of type:
* [PICKER_TYPE_DATE](Titanium.UI.PICKER_TYPE_DATE) or [PICKER_TYPE_TIME](Titanium.UI.PICKER_TYPE_TIME)
that also have [datePickerStyle](Titanium.UI.Picker.datePickerStyle) set to
[DATE_PICKER_STYLE_COMPACT](Titanium.UI.DATE_PICKER_STYLE_COMPACT).
* [PICKER_TYPE_PLAIN](Titanium.UI.PICKER_TYPE_PLAIN) that also have property
[useSpinner](Titanium.UI.Picker.useSpinner) set `false` to show a drop-down picker.
type: String
default: undefined
platforms: [android]
since: "10.0.1"
- name: locale
summary: Locale used when displaying Date and Time picker values.
description: |
Applicable to <Titanium.UI.PICKER_TYPE_DATE>, <Titanium.UI.PICKER_TYPE_TIME> and
<Titanium.UI.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](http://en.wikipedia.org/wiki/ISO_639-1) and
[ISO 3166-1 alpha-2](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements)
sections of wikipedia for reference.
On iOS, the system locale is always used.
type: String
default: System Settings
platforms: [android]
- name: maxDate
summary: Maximum date displayed when a Date picker is in use.
description: |
Applicable to <Titanium.UI.PICKER_TYPE_DATE> and <Titanium.UI.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](http://momentjs.com/docs/#/parsing/string/),
which includes ISO-8601 and RFC2822 dates.
This property is ignored when `maxDate` is less than `minDate`.
type: Date
- name: minDate
summary: Minimum date displayed when a Date picker is in use.
description: |
Applicable to <Titanium.UI.PICKER_TYPE_DATE> and <Titanium.UI.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](http://momentjs.com/docs/#/parsing/string/),
which includes ISO-8601 and RFC2822 dates.
This property is ignored when `maxDate` is less than `minDate`.
type: Date
- name: minuteInterval
summary: |
Interval in minutes displayed when one of the Time types of pickers is in use.
description: |
Applicable to <Titanium.UI.PICKER_TYPE_TIME> and <Titanium.UI.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.
type: Number
default: 1
platforms: [iphone, ipad, macos]
- name: selectionIndicator
summary: |
Determines whether the visual selection indicator is shown.
description: |
As of Titanium 10.0.1, this property will be ignored and Android will always show an indicator.
type: Boolean
default: true
platforms: [android]
deprecated:
since: "10.0.1"
notes: This property is ignored as of Titanium 10.0.1.
- name: selectionOpens
summary: |
Determines whether calling the method `setSelectedRow` opens when called
description: |
If `true`, selection will open when `setSelectedRow` is called.
If `false`, selection will not open when `setSelectedRow` is called.
type: Boolean
default: false (Android)
platforms: [android]
since: "5.0.0"
- name: datePickerStyle
summary: Determines how a date or time picker should appear.
description: |
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](Titanium.UI.Picker.type) property is set to
<Titanium.UI.PICKER_TYPE_PLAIN>.
type: Number
availability: creation
platforms: [android, iphone, ipad, macos]
since: {android: 10.0.1, iphone: 9.2.0, ipad: 9.2.0, macos: 9.2.0}
constants: Titanium.UI.DATE_PICKER_STYLE_*
default: <Titanium.UI.DATE_PICKER_STYLE_AUTOMATIC>
osver: { ios: { min: "13.4" } }
- name: type
summary: Determines the type of picker displayed
description: |
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.
type: Number
constants: Titanium.UI.PICKER_TYPE_*
default: <Titanium.UI.PICKER_TYPE_PLAIN>
- name: useSpinner
summary: Determines if a multicolumn spinner or single column drop-down picker should be used.
description: |
This property is intended to be used by plain picker types. When set on date/time pickers,
this property will override the [datePickerStyle](Titanium.UI.Picker.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](Titanium.UI.Picker.nativeSpinner) property worked in older versions.
On older Titanium versions, this property shows a non-native custom spinner view.
type: Boolean
default: false
availability: creation
platforms: [android]
- name: nativeSpinner
summary: Determines if a multicolumn spinner or single column drop-down picker should be used.
description: |
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](Titanium.UI.Picker.datePickerStyle) property is used.
As of Titanium 10.0.1, this property has the same effect as the
[useSpinner](Titanium.UI.Picker.useSpinner) property which also shows a native spinner.
``` js
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)
});
```
type: Boolean
default: false
availability: creation
platforms: [android]
since: "5.4.0"
- name: value
summary: Date and time value for Date and Time pickers.
description: |
Applicable to <Titanium.UI.PICKER_TYPE_DATE>, <Titanium.UI.PICKER_TYPE_TIME> and <Titanium.UI.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](http://momentjs.com/docs/#/parsing/string/),
which includes ISO-8601 and RFC2822 dates.
type: Date
- name: visibleItems
summary: |
Number of visible rows to display. This is only applicable to a plain picker and when the
`useSpinner` is `true`.
description: |
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.
type: Number
default: 5
platforms: [android]
deprecated:
since: "10.0.1"
notes: This property is ignored as of Titanium 10.0.1.
- name: calendarViewShown
summary: |
Determines whether the calenderView is visible.
description: |
If 'calendarViewShown' is 'true', the calenderView is visible
type: Boolean
default: false
platforms: [android]
- name: font
summary: Font to use for text.
description: |
Only applicable to <Titanium.UI.PICKER_TYPE_DATE> and <Titanium.UI.PICKER_TYPE_TIME>
picker types for android. For <Titanium.UI.PICKER_TYPE_PLAIN>, refer to <Titanium.UI.PickerColumn>
for android, and <Titanium.UI.PickerRow> for iphone / ipad.
type: Font
platforms: [android]
- name: color
summary: Text color of the Picker
type: [String, Titanium.UI.Color]
platforms: [android]
availability: creation
since: { android: "12.0.0"}
examples:
- title: Multi-Column Picker using Alloy XML Markup
example: |
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`:
``` 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`:
``` js
$.win.open();
```
- title: Date Picker using Alloy XML Markup
example: |
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`:
``` 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`:
``` js
function report(e) {
Ti.API.info('User selected: ' + e.value);
}
$.index.open();
```
- title: Basic Single Column Picker
example: |
Create a one-column, platform-specific style, picker and automatically select a row.
``` js
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
```
- title: Multi-Column Picker
example: |
Create a two-column, platform-specific style, picker and automatically select a row in
each column.
``` js
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
```
- title: Date Picker
example: |
Create a date picker and handle the subsequent user action.
``` js
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());
});
```
- title: Date Picker using showDatePickerDialog() (Android only)
example: |
Create a date picker that is automatically displayed as a modal dialog and handle the
subsequent user action.
``` js
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);
}
}
});
```