RadioButton练习心得

这是Test.xml内的内容

<?xml version="1.0" econding="UTF-8" ?>
<root>
<test>
单选题:请选择以下正确的描述:
</test>
<txt>
ActionScript3.0的运行环境是AVM2
</txt>
<txt>
ActionScript3.0的运行环境是JVM
</txt>
<txt>
MovieClip类是display类的子类
</txt>
<txt>
Sprite类是MovieClip类的子类
</txt>
<test>
下列对类的继承关系描述错误的是:
</test>
<txt>
Bitmap-->DisplayObject-->EventDispatcher-->Object
</txt>
<txt>
Shape-->Sprite-->DisplayObject-->EventDispatcher
</txt>
<txt>
Graphics-->Object
</txt>
<txt>
Label-->UIComponent-->Sprite-->DisplayObjectContainer
</txt>
<test>
以下哪个类不在flash.display包中
</test>
<txt>
SimpleButton
</txt>
<txt>
Graphics
</txt>
<txt>
Rectagle
</txt>
<txt>
BitmapData
</txt>
<test>
for each(var obj:Object in arr){}中的obj代表:
</test>
<txt>
遍历数组过程中,正在被遍历的那个元素
</txt>
<txt>
数组的索引值
</txt>
<txt>
数组中的第一个元素
</txt>
<txt>
数组中的最后的一个元素
</txt>
<test>
BitmapData类的transparent属性描述:
</test>
<txt>
位图图像是否支持每个像素具有不同的透明度
</txt>
<txt>
位图图像的颜色变换
</txt>
<txt>
位图图像的RGB值
</txt>
<txt>
BitmapData的透明度
</txt>
</root>

代码部分

package
{

import flash.display.MovieClip;
import fl.controls.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextFormat;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;

public class radiobtnMain extends MovieClip
{

private var myRadioBtn:RadioButton;
private var urlLoader:URLLoader = new URLLoader();
private var myTest:URLRequest = new URLRequest("Test.xml");
private var arr:Array = [];
private var labels:Label;
private var arr1:Array = [];
private var btn:Button = new Button();
private var txt:TextField = new TextField();
private var zu1:RadioButtonGroup = new RadioButtonGroup("group1");  // RadioButtonGroup可以将多个RadioButton放在此组里
private var zu2:RadioButtonGroup = new RadioButtonGroup("group2");
private var zu3:RadioButtonGroup = new RadioButtonGroup("group3");
private var zu4:RadioButtonGroup = new RadioButtonGroup("group4");
private var zu5:RadioButtonGroup = new RadioButtonGroup("group5");
public function radiobtnMain()
{
radioBtn();
btn.x = 400;
btn.y = 550;
btn.label = "确定";
txt.x = 300;
txt.y = 545;
txt.border = true;
txt.width = 80;
txt.height = 30;
stage.addChild(txt);
stage.addChild(btn);
btn.addEventListener(MouseEvent.CLICK,onClickHandler);

}
private function onClickHandler(e:MouseEvent):void
{
panduan();

}

private function panduan():void
{
var num:uint = 0;
if (zu1.getRadioButtonAt(0).selected == true)   //getRadioButtonAt(index:int)是检索RadioButtonGroup

                        //指定索引位置的 RadioButton 组件。其中第一个组件的索引为 0
{
num += 20;
}
if (zu2.getRadioButtonAt(1).selected == true)
{
num += 20;
}
if (zu3.getRadioButtonAt(2).selected == true)
{
num += 20;
}
if (zu4.getRadioButtonAt(0).selected == true)
{
num += 20;
}
if (zu5.getRadioButtonAt(0).selected == true)
{
num += 20;
}
txt.text = String(num);
}

private function radioBtn():void
{
for (var i:uint = 0; i < 20; i++)
{
myRadioBtn = new RadioButton();
var txtFormat:TextFormat = new TextFormat("宋体",12,0x000000);
myRadioBtn.setStyle("textFormat",txtFormat);
urlLoader.load(myTest);
urlLoader.addEventListener(Event.COMPLETE,onGetXmlHandler);
arr.push(myRadioBtn);

}
}
private function onGetXmlHandler(e:Event):void
{

var xml:XML = new XML(urlLoader.data);
//trace(xml.txt);
for (var j:uint = 0; j < 20; j++)
{
arr[j].label = (xml.txt[j]);
arr[j].width = 500;
arr[j].x = 20;
arr[j].y = j * 30 + 10.5;
stage.addChild(arr[j]);
//trace (arr[j])
for (var a:uint = 0; a < 4; a++)
{
zu1.addRadioButton(arr[a]);
}
for (var b:uint = 4; b < 8; b++)
{
zu2.addRadioButton(arr[b]);
}
for (var c:uint = 8; c < 12; c++)
{
zu3.addRadioButton(arr[c]);
}
for (var d:uint = 12; d < 16; d++)
{
zu4.addRadioButton(arr[d]);
}
for (var f:uint = 16; f < 20; f++)
{
zu5.addRadioButton(arr[f]);
}


for (var m:uint = 0; m < 5; m++)
{

labels = new Label();
var txtFormat:TextFormat = new TextFormat("宋体",14,0x000000);
labels.setStyle("textFormat",txtFormat);
labels.width = 300;
arr1.push(labels);
arr1[m].text = (xml.test[m]);
arr1[m].x = 20;
arr1[m].y = m * 118;
stage.addChild(arr1[m]);
}
}

}
}

}

转载于:https://www.cnblogs.com/yanshuoistutu/archive/2012/10/16/2726932.html

RadioButton是Android中的一个单选按钮控件,通常用于让用户从多个选项中选择一个选项。它与CheckBox控件相似,但是RadioButton只能选择其中的一个选项,而CheckBox可以选择多个选项。 使用RadioButton控件通常需要将多个RadioButton放在同一个RadioGroup中,这样才能使它们之间产生互斥关系,即在同一时间只能选中一个RadioButton。 以下是一个简单的RadioButton的使用示例: 在XML布局文件中: ``` <RadioGroup android:id="@+id/radio_group" android:layout_width="wrap_content" android:layout_height="wrap_content"> <RadioButton android:id="@+id/radio_button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="选项1" /> <RadioButton android:id="@+id/radio_button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="选项2" /> <RadioButton android:id="@+id/radio_button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="选项3" /> </RadioGroup> ``` 在Java代码中: ``` RadioGroup radioGroup = findViewById(R.id.radio_group); RadioButton radioButton1 = findViewById(R.id.radio_button1); RadioButton radioButton2 = findViewById(R.id.radio_button2); RadioButton radioButton3 = findViewById(R.id.radio_button3); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, int i) { // 选中的RadioButton发生变化时的处理逻辑 if (i == R.id.radio_button1) { // 选中第一个选项的处理逻辑 } else if (i == R.id.radio_button2) { // 选中第二个选项的处理逻辑 } else if (i == R.id.radio_button3) { // 选中第三个选项的处理逻辑 } } }); ``` 在代码中,我们首先通过findViewById()方法获取到RadioGroup和RadioButton控件的实例,然后通过setOnCheckedChangeListener()方法设置监听器,当选中的RadioButton发生变化时会调用onCheckedChanged()方法,我们可以在该方法中根据选中的RadioButton的id来执行相应的逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值