[原] 怎么让ButtonBar默认没有选中的Button

[说明: 本文为 http://www.smithfox.com/?e=43 原创, 转载请注明原文, 谢谢]

这是一个小问题,还真不太容易在网上找到答案。

默认不选中 其实很简单, 将 ButtonBar.requireSelection 属性设置为false就可以了。问题是这样一来,ButtonBar中的Button在选择状态下再click一次又可以变成了非选中状态。相信有些同学有和我一样的需求: 开始没有任何Button被选中, 用户一旦click后,就必须而且只能选择一个Button.

我的做法是,在mxml tag中默认先将requireSelection设置为false, 然后在ButtonBar的change事件中将该属性改为true.

<s:ButtonBar height="28" width="100%" change="onButtonBarChange(event);">

public function onButtonBarChange(event:IndexChangeEvent):void {
	//here, you can do some other logic
	//xxx

	//following code resolve no default button for ButtonBar
	var lb:ButtonBarBase = event.target as ButtonBarBase;
	if ( ! lb.requireSelection ) {
		lb.requireSelection = true;
	}
}

[说明: 本文为 http://www.smithfox.com/?e=43 原创, 转载请注明原文, 谢谢]

smithfox | Thursday 06 January 2011 at 1:51 pm | | UI        | Used tags: , , ,

three comments

小残

我设置了requireSelection为false,但是还是一运行就默认第一个选中呢。。。。

小残, (URL) - 10-06-’11 10:12
smithfox

找到原因了吗? 你将 code email 给我看看

smithfox, (URL) - 10-06-’11 10:27
Chanel iPhone 6 Plus Wallet Cases

The versatility of Android is well represented on the Nexus 9, allowing you to install third party Launchers, add tweaks as might be found in our Android customization series and so much more.

Chanel iPhone 6 Plus Wallet Cases, (URL) - 20-04-’15 18:30
(optional field)
(optional field)
为阻止垃圾广告, 请在提交评论前, 回答一个简单问题(Please answer an simple question)
Remember personal info?
Notify
Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.