Skip to main content
Version: v1.0

CHECKBOX_GROUP

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

const checkGroup = hmUI.createWidget(hmUI.widget.CHECKBOX_GROUP, checkboxGroupParam)
const stateButton = hmUI.createWidget(hmUI.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 hmUI.prop.INIT to render the view

Prop Properties

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

Code example

tip

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

Page({
build() {
const checkbox_group = hmUI.createWidget(hmUI.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(hmUI.widget.STATE_BUTTON, {
x: 40,
y: 200,
w: 64,
h: 64
})
const button2 = checkbox_group.createWidget(hmUI.widget.STATE_BUTTON, {
x: 190,
y: 200,
w: 64,
h: 64
})
const button3 = checkbox_group.createWidget(hmUI.widget.STATE_BUTTON, {
x: 340,
y: 200,
w: 64,
h: 64
})

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