List Picker
The ListPicker is a spinner type component for listing options.
Usage
The example demonstrates how to set a ListPicker in XML page, how to bind its selectedIndex property and to handle its change.
Styling
Tips And Tricks
Using key-value pairs
This functionality provides a simple way to specify the text field, which will be displayed in the ListPicker and the value field which will be returned as a result. In this scenario, when we are setting JSON object to the ListPicker's source, we should set up the textField and valueField properties, which will specify the displayed and result values. In the example below we are setting textField to name and valueField to role. This means that all properties marked as name will be displayed in the component and as a result, we will receive their corresponding role. We are receiving the selected value via selectedValue property, which can also be accessed via code-behind.
Creating ListPicker via Code-Behind
Creating a ListPicker programmatically while setting items source and default selected index.
Properties
| Name | Type | Description |
|---|---|---|
items |
Array<any> |
Gets or set the items collection of the ListPicker. The items property can be set to an array or an object defining length and getItem(index) method. |
selectedIndex |
number |
Gets or set the items collection of the ListPicker. The items property can be set to an array or an object defining length and getItem(index) method. |
Events
| Name | Description |
|---|---|
selectedIndexChange |
Emitted when the selectedIndex is changed. |
API References
| Name | Type |
|---|---|
| tns-core-modules/ui/list-picker | Module |
| ListPicker | Class |
Native Component
| Android | iOS |
|---|---|
| android.widget.NumberPicker | UIPickerView |