1# Text Picker Dialog Box 2 3A text picker dialog box is a dialog box that allows users to select text from the given range. 4 5> **NOTE** 6> 7> The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. 8 9 10## TextPickerDialog.show 11 12show(options?: TextPickerDialogOptions) 13 14Shows a text picker in the given settings. 15 16**TextPickerDialogOptions** 17 18| Name| Type| Mandatory| Description| 19| -------- | -------- | -------- | -------- | 20| range | string[] \| [Resource](ts-types.md#resource) | Yes| Data selection range of the picker.| 21| selected | number | No| Index of the selected item.<br>Default value: **0**| 22| value | string | No | Text of the selected item. This parameter does not take effect when the **selected** parameter is set. If the value is not within the range, the first item in the range is used instead.| 23| defaultPickerItemHeight | number \| string | No| Height of the picker item.| 24| onAccept | (value: [TextPickerResult](#textpickerresult)) => void | No| Callback invoked when the OK button in the dialog box is clicked.| 25| onCancel | () => void | No| Callback invoked when the Cancel button in the dialog box is clicked.| 26| onChange | (value: [TextPickerResult](#textpickerresult)) => void | No| Callback invoked when the selected item changes.| 27 28## TextPickerResult 29 30| Name| Type| Description| 31| -------- | -------- | -------- | 32| value | string | Text of the selected item.| 33| index | number | Index of the selected item in the range.| 34 35## Example 36 37```ts 38// xxx.ets 39@Entry 40@Component 41struct TextPickerDialogExample { 42 @State select: number = 2 43 private fruits: string[] = ['apple1', 'orange2', 'peach3', 'grape4', 'banana5'] 44 45 build() { 46 Column() { 47 Button("TextPickerDialog") 48 .margin(20) 49 .onClick(() => { 50 TextPickerDialog.show({ 51 range: this.fruits, 52 selected: this.select, 53 onAccept: (value: TextPickerResult) => { 54 // Set select to the index of the item selected when the OK button is touched. In this way, when the text picker dialog box is displayed again, the selected item is the one last confirmed. 55 this.select = value.index 56 console.info("TextPickerDialog:onAccept()" + JSON.stringify(value)) 57 }, 58 onCancel: () => { 59 console.info("TextPickerDialog:onCancel()") 60 }, 61 onChange: (value: TextPickerResult) => { 62 console.info("TextPickerDialog:onChange()" + JSON.stringify(value)) 63 } 64 }) 65 }) 66 }.width('100%') 67 } 68} 69``` 70