beetlebug▾
/

ztk::android::Picker

Makes a picker of one item from a list: a drop-down list (Spinner) that shows the selected item and opens the list.

Synopsis

ztk::android::Picker new ?OPTION VALUE ...?
$screen add picker ?OPTION VALUE ...?

Arguments

Name Type Default Description
-items list empty The titles of the items. A new list keeps the selected index when it is still an index of the list, and otherwise selects the first item. new and add set -items before -selected.
-selected integer 0 The index of the selected item, from 0. A choice of the user changes it; cget reads it from the view.
-command script empty Runs with the object appended after a choice of the user.
-enabled boolean 1 0 dims the control, and a tap does nothing.
invoke INDEX method Selects the item INDEX and runs -command, as a choice of the user does (for tests).
-hidden, -accessibilityLabel, -accessibilityHint option As for each view (ztk::android).
configure, cget, destroy method As for each object (ztk::android).

Return value

new gives the object.

Errors

Error When
bad selected "X": must be an index from 0 to N -selected is no index of the items.
bad selected "X": the list of items is empty -selected is not 0, and there is no item.
expected boolean value but got "X" -enabled is no boolean.
unknown option "-X": must be ... Another option.

Platforms

Platform Works
Windows No
macOS No
Linux, Wayland No
Linux, X11 No
Web No
iOS No: ztk::ios::Picker
Android Yes
Headless With --fake-native android: fake views for a test (Test on a desktop).

Example

set screen [ztk::android::Screen new -title Card]
$screen add picker -items {10 9.5 9 8.5} -selected 2 \
    -command {apply {{p} {puts "grade [lindex [$p cget -items] [$p cget -selected]]"}}}
ztk::android::app root $screen

See also