EUI RadioButton,RadioButtonGroup实现多选项按钮


 

官网单选框教程:http://developer.egret.com/cn/github/egret-docs/extension/EUI/controls/radioButton/index.html

 

这里和官网教程不一样,官网是在代码里设置RadioButtonGroup,以及RadioButton的value值。

这里是在exml中源码里设置。

 

一 自动创建的RadioButtonGroup

RadioButtonGroup不能在exml里拖动创建,也不能在exml源码里创建。因为wing没提供...

一个exml上摆放的多个RadioButton,未指定groupName情况下,会为他们自动创建一个唯一RadioButtonGroup。

 

 

若需要手动为这些RaidoButton分组,则需要在exml源码里设置groupName属性。

下面代码为两个RadioButton分别指定groupName为“a”和“b”,相当于创建了两个RadioButtonGroup。

<e:RadioButton id="rd1" label="单选框" x="71" y="117" value="1" groupName="a"/>
<e:RadioButton id="rd2" label="单选框" x="70" y="174" value="2" groupName="b"/>

 

二 监听单选事件

因为exml上没有RadioButtonGroup,所以只能监听任意一个RadioButton,调用RadioButton.group值来获取RadioButtonGroup。

private rd1:eui.RadioButton; public childrenCreated(){ this.rd1.group.addEventListener(egret.Event.CHANGE, this.onChange, this); } private onChange(e:egret.Event){ var rbGroup:eui.RadioButtonGroup = e.target; console.log(rbGroup.selectedValue); //点击的RadioButton对象的value值 console.log(rbGroup.selection); //点击的RadioButton对象 }

 

RadioButton的value值需要在exml源码里设置。

若没有手动设置value值,则会自动将label值作为value值。

下面代码为两个RadioButton设置value值为“1”和“2”。

<e:RadioButton id="rd1" label="单选框" x="71" y="117" value="1"/>
<e:RadioButton id="rd2" label="单选框" x="70" y="174" value="2"/>

 

三 设置RadioButton皮肤

可直接在快捷面板中设置正常、按下等皮肤

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM