ztk::android::Segmented
Makes a segmented control: a row of buttons of equal width. A tap on an item selects it. The framework of Android has no segmented control: the selected button is filled, and the others are tinted.
Synopsis
ztk::android::Segmented new ?OPTION VALUE ...?
$screen add segmented ?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. -1 selects no item. 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 -1 or 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. |
| Platform |
Works |
| Windows |
No |
| macOS |
No |
| Linux, Wayland |
No |
| Linux, X11 |
No |
| Web |
No |
| iOS |
No: ztk::ios::Segmented |
| 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 segmented -items {Raw Graded Sealed} -selected 1 \
-command {apply {{c} {puts [lindex [$c cget -items] [$c cget -selected]]}}}
ztk::android::app root $screen
See also