Skip to main content
Version: v3

CHECKBOX_GROUP

Start from API_LEVEL 2.0 . Please refer to API_LEVEL.

check_group_sample

Used to select a single result among multiple options. Each individual option needs to be created using STATE_BUTTON.

Create UI widget

import { createWidget, widget } from '@zos/ui'

const checkGroup = createWidget(widget.CHECKBOX_GROUP, checkboxGroupParam)
const stateButton = createWidget(widget.STATE_BUTTON, stateButtonParam)

Type

checkboxGroupParam: object

PropertiesDescriptionRequiredType
xThe x-coordinate of widgets.YESnumber
yThe y-coordinate of widgets.YESnumber
wThe width of widgets.YESnumber
hThe height of widgets.YESnumber
select_srcThe selected image of the widgets.YESstring
unselect_srcThe unselected image of the widgets.YESstring
check_funcCallback when button state changes.NOCheckFunc

CheckFunc: function

(checkboxGroup: CheckboxGroup, index: number, checked: boolean) => void
ParametersDescriptionType
checkboxGroupThe instance of checkboxGroup.CheckboxGroup
indexSubview index for state changesnumber
checkedCheck or notboolean

StateButton

PropertiesRequiredTypeNotes
xYESnumberThe x-coordinate of widgets. Coordinates relative to checkboxGroup.
yYESnumberThe y-coordinate of widgets. Coordinates relative to checkboxGroup.
wYESnumberThe width of widgets.
hYESnumberThe height of widgets.
caution

The widget must be initialized once with prop.INIT to render the view

Prop Properties

PropertiesSupports get/setTypeNotes
prop.INITsetobjectInitialize the widget and set the default checkbox
prop.CHECKEDset/getobject(Returns the bool type when get)Set selected sub-widget.Get the selected state of the sub-widget.
prop.UNCHECKEDsetobjectSet unchecked sub-widget.

Code example

tip

Please refer to Design Resources for the image resources in the code example

import { createWidget, widget, prop } from '@zos/ui'

Page({
build() {
const checkbox_group = createWidget(widget.CHECKBOX_GROUP, {
x: 0,
y: 0,
w: 480,
h: 64,
select_src: 'selected.png',
unselect_src: 'unselected.png',
check_func: (group, index, checked) => {
console.log('index', index)
console.log('checked', checked)
}
})

const button1 = checkbox_group.createWidget(widget.STATE_BUTTON, {
x: 40,
y: 200,
w: 64,
h: 64
})
const button2 = checkbox_group.createWidget(widget.STATE_BUTTON, {
x: 190,
y: 200,
w: 64,
h: 64
})
const button3 = checkbox_group.createWidget(widget.STATE_BUTTON, {
x: 340,
y: 200,
w: 64,
h: 64
})

checkbox_group.setProperty(prop.INIT, button2)
checkbox_group.setProperty(prop.CHECKED, button3)
}
})