×

radiobutton怎么设置二选一

radiobutton怎么设置二选一(假设设置了2个RadioButton,在代码中如何去实现选中其一就不能选另一个)

admin admin 发表于2024-01-23 18:17:14 浏览40 评论0

抢沙发发表评论

大家好,如果您还对radiobutton怎么设置二选一不太了解,没有关系,今天就由本站为大家分享radiobutton怎么设置二选一的知识,包括假设设置了2个RadioButton,在代码中如何去实现选中其一就不能选另一个的问题都会给大家分析到,还望可以解决大家的问题,下面我们就开始吧!

本文目录

假设设置了2个RadioButton,在代码中如何去实现选中其一就不能选另一个

  两个RadioButton要写在同一个组RadioGroup下面这样就可以了...xml文件如下:\x0d\x0a  \x0d\x0a  \x0d\x0a  \x0d\x0a  \x0d\x0a  java代码如下:\x0d\x0a  private RadioGroup rg_sex ;\x0d\x0a  ...\x0d\x0a  rg_sex = (RadioGroup)findViewById(R.id.rg_sex);\x0d\x0a  rg_sex.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {\x0d\x0a  @Override\x0d\x0a  public void onCheckedChanged(RadioGroup group, int checkedId) {\x0d\x0a  switch (checkedId) {\x0d\x0a  case R.id.rb_person_man:\x0d\x0a  System.out.println("男");\x0d\x0a  break;\x0d\x0a  case R.id.rb_person_woman:\x0d\x0a  System.out.println("女");\x0d\x0a  break ;\x0d\x0a  default:\x0d\x0a  break;\x0d\x0a  }\x0d\x0a  }\x0d\x0a  });

android 二选一的按钮用什么控件

android如何要实现二选一的功能的话,可以使用radio,单选按钮,只能同时选择一个

c# Form1中两个radiobutton,选择其一,在Form2显示不同的提示语句怎么实现

Form1的关键代码Form1中两个radiobutton分别为yes,no,选择其一,并点击buttonnamespace BaiduKnowTest{ public partial class Form1 : Form { Form2 newFrm = new Form2(); public Form1() { InitializeComponent(); newFrm.Show(); //你显示Form2的方式不一定要跟我一样的。只要是全局的Form2变量即可 } private void button1_Click(object sender, EventArgs e) { if (rbnYes.Checked) {//选择yes,要显示什么自己改。 newFrm.ChangeLableText("You choose yes!"); return; } if (rbnNo.Checked) {//选择no newFrm.ChangeLableText("You choose No!"); return; } } }}Form2的关键代码namespace BaiduKnowTest{ public partial class Form2 : Form { public Form2() { InitializeComponent(); } public void ChangeLableText(string text) {//这个函数接收要显示的语句 label1.Text = text; } }}有困难可HI我。

table里怎样控制2 个RadioButton只能选一个

1.如图所示。

还有1种你用RadioButtonList1 然後在他属性的 Items...维护两个选项即可,

两个单选框怎么实现二选一matlab

这是SWING图形化界面把 直接用鼠标拖拽多好,弄一个绝对布局,添加一个JRadioButton,我经常用鼠标托,方便 在AWT中是通过复选框组CheckBoxGroup来实现单选框的功能的,而在Swing中则直接提供了一个单选框JRadioButton。

C# 两个checkbox 选且只选一个应该怎么写

这种只能二选一或者多选一的情况一般都是使用RadioButton我看你这应该是WinForm,用radioButton,设置两个RadioButton的RadioGroup(应该是这个属性,我能肯定的是什么什么Group)属性为一样的,比方说都设置为 1 ,或者 2 或者其他。如果只想使用CheckBox,那就在CheckBox上加事件,判断:男被选中,女就取消选中。女被选中,男就取消选中if(CheckBox_boy.Checked) CheckBox_Girl.Checked = false;if(CheckBox_Girl.Checked) CheckBox_boy.Checked = false;

android RadioButton问题,如何实现只能选择一个呢

  两个RadioButton要写在同一个组RadioGroup下面这样就可以了...xml文件如下:  《RadioGroup android:id="@+id/rg_sex" android:layout_width="fill_parent"  android:orientation="horizontal" android:layout_height="wrap_content"》  《RadioButton android:layout_width="wrap_content"  android:text="@string/person_man" android:id="@id/+rb_person_man"  android:layout_height="wrap_content" android:checked="true" /》  《RadioButton android:layout_width="wrap_content"  android:text="@string/person_woman" android:id="@id/+rb_person_woman"  android:layout_height="wrap_content" /》  《/RadioGroup》  java代码如下:  private RadioGroup rg_sex ;  ...  rg_sex = (RadioGroup)findViewById(R.id.rg_sex);  rg_sex.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {  @Override  public void onCheckedChanged(RadioGroup group, int checkedId) {  switch (checkedId) {  case R.id.rb_person_man:  System.out.println("男");  break;  case R.id.rb_person_woman:  System.out.println("女");  break ;  default:  break;  }  }  });

关于radiobutton怎么设置二选一和假设设置了2个RadioButton,在代码中如何去实现选中其一就不能选另一个的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。