
复制代码 代码如下:
public class MainActivity extends Activity {
public RadioGroup mRadioGroup1;
public Radiobutton mRadio1,mRadio2;
@OverrIDe
protected voID onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentVIEw(R.layout.activity_main);
mRadioGroup1 = (RadioGroup) findVIEwByID(R.ID.gendergroup);
mRadio1 = (Radiobutton) findVIEwByID(R.ID.girl);
mRadio2 = (Radiobutton) findVIEwByID(R.ID.boy);
mRadioGroup1.setonCheckedchangelistener(radiogpchange);
}
private RadioGroup.OnCheckedchangelistener radiogpchange = new RadioGroup.OnCheckedchangelistener() {
@OverrIDe
public voID onCheckedChanged(RadioGroup group,int checkedID) {
if (checkedID == mRadio1.getID()) {
Toast.makeText(getApplicationContext(),"女孩",1).show();
} else if (checkedID == mRadio2.getID()) {
Toast.makeText(getApplicationContext(),"男孩",1).show();
}
}
};
}
Radiobutton:就像是C#中的Radio控件,可以为控件设置Group,每个Group中的项只能选择一项;
复制代码 代码如下:
<RadioGroup
androID:ID="@+ID/gendergroup"
androID:layout_wIDth="fill_parent"
androID:layout_height="wrap_content"
androID:orIEntation="vertical" >
<Radiobutton
androID:ID="@+ID/girl"
androID:layout_wIDth="fill_parent"
androID:layout_height="wrap_content"
androID:text="@string/girl" />
<Radiobutton
androID:ID="@+ID/boy"
androID:layout_wIDth="fill_parent"
androID:layout_height="wrap_content"
androID:text="@string/boy" />
</RadioGroup>
以上是内存溢出为你收集整理的Android RadioButton单选框的使用方法全部内容,希望文章能够帮你解决Android RadioButton单选框的使用方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)