-
radioButton控件的使用方法
2018-10-12 14:42:36radioButton控件的使用方法 radioButton控件的定义 private RadioGroup rg; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.explain); rg=...radioButton控件的使用方法
radioButton控件的定义
private RadioGroup rg; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.explain); rg=(RadioGroup)findViewById(R.id.radio_group); //定义radioGroup控件 rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {//表示RadioGroup中的radioButton状态切换时触发的监听 @Override public void onCheckedChanged(RadioGroup radioGroup, int checkedId) { RadioButton rb = (RadioButton)findViewById(checkedId); //选中radioButton的对象资源id获取radioButton对象 String str = rb.getText().toString();//获取选中radioButton的文本 Toast.makeText(Explain.this,"Hello"+str,Toast.LENGTH_SHORT).show(); } }); }
将radioButton圆点去除
<style name="Radio_style"> <item name="android:layout_width">0dp</item> <item name="android:padding">3dp</item> <item name="android:layout_height">match_parent</item> <item name="android:layout_weight">1</item> <item name="android:button">@null</item><!--去除RadioButton默认带的圆点--> <item name="android:gravity">center</item> <item name="android:textSize">12sp</item> </style>
布局xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_alignParentBottom="true"> <RadioGroup android:id="@+id/radio_group" android:layout_width="match_parent" android:layout_height="56dp" android:background="#FFFFFF" android:orientation="horizontal" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true"> <RadioButton android:text="首页" android:textSize="20sp" style="@style/Radio_style" android:id="@+id/radioButton" android:background="@mipmap/ic_launcher" android:checked="false" /> <RadioButton android:text="联系人" android:textSize="20sp" style="@style/Radio_style" android:id="@+id/radioButton2" /> <RadioButton android:text="推荐" android:textSize="20sp" style="@style/Radio_style" android:id="@+id/radioButton3" /> <RadioButton android:text="个人中心" android:textSize="20sp" style="@style/Radio_style" android:id="@+id/radioButton4" /> </RadioGroup> </RelativeLayout>
-
Android控件系列之RadioButton与RadioGroup使用方法
2020-09-05 18:21:43本文介绍了Android中如何使用RadioGroup和RadioButton,对比了RadioButton和CheckBox的区别,并实现了自定义的RadioGroup中被选中RadioButton的变更监听事件 -
【Android 开发】:UI控件之单选按钮 RadioButton 的使用方法
2013-05-31 22:53:18这一讲我们来学习一下 UI控件中 RadioButton 的使用方法 选项按钮可以用于多选一的应用中,如果想在选中的某一个选项按钮后,其它的选项按钮都被设置为未选中的状态,需要将添加到标签中。 主要代码: ...这一讲我们来学习一下 UI控件中 RadioButton 的使用方法
选项按钮可以用于多选一的应用中,如果想在选中的某一个选项按钮后,其它的选项按钮都被设置为未选中的状态,需要将<RadioButton>添加到<RadioGroup>标签中。
主要代码:
button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub int len = group.getChildCount(); // 获得单选按钮组的选项个数 String msgString = ""; // 给选中的选项值赋值用的,初始化为空 for (int i = 0; i < len; i++) { RadioButton radioButton = (RadioButton) group.getChildAt(i); // 返回Group里的指定位置的视图(也就是按钮了)。 /* * 查看android api 文档RadioButton的 public boolean isChecked * ()方法 如果未找到这个方法,往父类上找到,这个方法是用检测是否按钮被选中 */ if (radioButton.isChecked()) { msgString = radioButton.getText().toString(); break; } } Toast.makeText(RadioButtonDemo.this, msgString, 1).show(); } });
布局文件:<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="性别:" /> <RadioGroup android:id="@+id/sex" android:layout_width="wrap_content" android:layout_height="wrap_content" > <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="男" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="女" /> </RadioGroup> <Button android:id="@+id/button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="选择性别" /> </LinearLayout>
程序Demo执行结果: -
Asp.net_GridView控件中添加的RadioButton的使用方法
2012-02-29 16:26:12//绑定前台页面的“单选控制js方法”事件 protected void 替换的GridView的身份_RowDataBound(object sender, GridViewRowEventArgs e) { //给每个RadioButton1绑定setRadio事件 try { ((RadioButton)e.Row....1.aspx
<script type="text/javascript"> //控制单选的js function setRadio(nowRadio) { var myForm,objRadio; myForm=document.forms[0]; ///alert(myForm); for(var i=0;i<myForm.length;i++) { if(myForm.elements[i].type=="radio") { objRadio=myForm.elements[i]; ///alert(objRadio.name); if(objRadio!=nowRadio && objRadio.name.indexOf("替换的GridView的身份")>-1 && objRadio.name.indexOf("替换的单选按钮身份")>-1) { //alert(objRadio.name); if(objRadio.checked) { objRadio.checked=false; } } } } } </script>
<asp:GridView ID="替换的GridView的身份" runat="server" AutoGenerateColumns="False" Width="100%" onrowdatabound="替换的GridView的身份_RowDataBound"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:RadioButton ID="替换的单选按钮身份" runat="server" oncheckedchanged="替换的单选按钮身份_CheckedChanged" AutoPostBack="true"/> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="字段名" HeaderText="显示的文本" /> <asp:BoundField DataField="字段名" HeaderText="显示的文本" /> <asp:BoundField DataField="字段名" HeaderText="显示的文本" /> </Columns> </asp:GridView>
1.aspx.cs
//绑定前台页面的“单选控制js方法”事件 protected void 替换的GridView的身份_RowDataBound(object sender, GridViewRowEventArgs e) { //给每个RadioButton1绑定setRadio事件 try { ((RadioButton)e.Row.FindControl("替换的单选按钮身份")).Attributes.Add("onclick", "setRadio(this)"); } catch (Exception) { } }
//确定按钮的事件 protected void btnOK_Click(object sender, EventArgs e) { for (int i = 0; i < this.替换的GridView的身份.Rows.Count; i++) { RadioButton 替换的单选按钮身份d = this.替换的GridView的身份.Rows[i].Cells[0].FindControl("替换的单选按钮身份") as RadioButton; if (替换的单选按钮身份d.Checked == true) { //获取数据 Session["名"] = this.替换的GridView的身份.Rows[i].Cells[1].Text; //获取数据 Session["名"] = this.替换的GridView的身份.Rows[i].Cells[2].Text; //获取数据 Session["名"] = this.替换的GridView的身份.Rows[i].Cells[3].Text; } }
-
asp.net button创建控件时出错_Tkinter Radiobutton控件
2020-12-29 08:00:28单选按钮可显示文字或图片,显示文字时只能使用预设字体,该控件可以绑定一个 Python 函数或方法,当单选按钮被选择时,该函数或方法将被调用。单选按钮(Radio Button)这个名字来源于收音机(Radio)上的调频按钮...单选按钮是一种可在多个预先定义的选项中选择出一项的 Tkinter 控件 。单选按钮可显
示文字或图片,显示文字时只能使用预设字体,该控件可以绑定一个 Python 函数或方
法,当单选按钮被选择时,该函数或方法将被调用。
单选按钮(Radio Button)这个名字来源于收音机(Radio)上的调频按钮, 这些按钮用
来选择特定波段或预设电台,如果一个按钮被按下, 其他同类的按钮就会弹起,即同时
只有一个按钮可被按下。
一组单选按钮控件和同一个变量关联。点击其中一个单选按钮将把这个变量设为某个预
定义的值。一般用法为: Radiobutton(myWindow,options) ,其中 option 与
Checkbutton,Button 大多重合,用法一致。实例:创建单选按钮并绑定响应函数,代码如下:
from tkinter import* #初始化Tk() myWindow=Tk() myWindow.title('Python GUI Learning') v=IntVar() #列表中存储的是元素是元组 language=[('python',0),('C++',1),('C',2),('Java',3)] #定义单选按钮的响应函数 def callRB(): for i in range(4): if (v.get()==i): root1 = Tk() Label(root1,text='你的选择是'+language[i][0]+'!',fg='red',width=20, height=6).pack() Button(root1,text='确定',width=3,height=1,command=root1.destroy).pack(side='bottom') Label(myWindow,text='选择一门你喜欢的编程语言').pack(anchor=W) #for循环创建单选框 for lan,num in language: Radiobutton(myWindow, text=lan, value=num, command=callRB, variable=v).pack(anchor=W) #进入消息循环 myWindow.mainloop()
运行结果:
相关学习资料:
Python Tkinter 绘图项目ke.qq.comPython Tkinter 数字时钟小项目edu.csdn.net -
[Tinkter 教程05] Radiobutton 控件
2017-03-07 01:12:01该控件可以绑定一个 Python 函数或方法, 当单选按钮被选择时, 该函数或方法将被调用. 单选按钮 (Radio Button) 这个名字来源于收音机 (Radio) 上的调频按钮, 这些按钮用来选择特定波段或预设电台. 如果一个按钮被 -
安卓控件使用系列10:RadioButton单选按钮的使用
2015-10-02 14:48:14下面将使用方法分享给大家。 这个例子实现的是性别的选择,选择男或女,点击按钮显示选择的信息。 主要思路:在一个RadioGroup控件中定义两个RadioButton控件,用于表示选择的性别男或女;定义Button控件的OnClick... -
[译][Tinkter 教程05] Radiobutton 控件
2018-04-10 16:28:16已获原作者授权. 原系列地址: Python Tkinter Radio Buttons 单选按钮是一种可在多个预先定义的选项中选择出... 该控件可以绑定一个 Python 函数或方法, 当单选按钮被选择时, 该函数或方法将被调用.单选按钮 (Radio... -
WPF自定义控件中使用了RadioButton后,多次使用该控件出现的死循环解决方法
2018-11-22 15:20:57最近在项目中需要用到RadioButton,所以在自定义控件中使用了一组RadioButton,使用一个默认的groupname,也就是这个goupname给后来的问题埋下了地雷。 定义大致如下: <Grid> <Label ... -
WPF RadioButton按钮控件取消选中设置
2020-09-18 08:27:50通常我们使用的RadioButton控件选中之后就不能进行取消选中的操作,我上网查找到了解决方法,如下: 首先我们在View视图这里写这个按钮的点击触发事件 然后来到后台,先声明一个变量来记录这个按钮的选中状态,然后... -
asp.net GridView中使用RadioButton单选按钮的方法
2021-01-02 13:47:17第一种方法:在GridView的模版列里加服务器端控件RadioButton,使用js控制单选 使用模版列里加RadioButton [removed] function setRadio(nowRadio) { var myForm,objRadio; myForm=document.forms[0]; /**////... -
android RadioButton和CheckBox组件的使用方法
2020-09-04 21:53:04本次实验中主要是学习如何使用RadioGroup,CheckBox,RadioButton和Toast这几个控件,android UI开发中也会经常用到他们 -
c# 控件RadioButton
2012-12-07 18:05:17在使用时直接把同一组的radiobutton放入到一个groupBox或者panel里面,他们就自动为一组了,在使用的时候(判断哪一个被选中)有两种方法 第一: foreach (Control ctrl in groupBox1.Controls) -
Android基础控件RadioGroup使用方法详解
2021-01-04 21:08:08本文为大家分享了Android基础控件RadioGroup的使用,供大家参考,具体内容如下 1.简单介绍 RadioGroup可以提供几个选项供用户选择,但只能选择其中的一个。其下面可以横着或者竖着挂几个RadioButton,也可以挂载其他... -
ASP.NET中 RadioButtonList 单选按钮组控件的使用方法
2021-01-02 21:34:24可以使用两种类型的 ASP.NET 控件将单选按钮添加到网页上:各个 RadioButton 控件或一个 RadioButtonList 控件。这两类控件都允许用户从一小组互相排斥的预定义选项中进行选择。使用这些控件,可定义任意数目的带... -
常用控件的使用方法
2013-03-12 17:16:21在 Android 中使用各种控件(View) TextView - 文本显示控件 Button - 按钮控件 ImageButton - 图片按钮控件 ImageView - 图片显示控件 CheckBox - 复选框控件 RadioButton - 单选框控件 AnalogClock -... -
RadioButton分组使用
2019-03-05 14:14:30把控件放在一个分组框group中 1. 分组 将radio1、radio2、radio3分为1组,radio4、radio5分为另一组; 方法:设置 radio1 的 属性: group、tabstop、auto均为true 设置 radio2 的 属性: group设为false,... -
Android控件中CheckBox、RadioButton详解
2016-06-18 14:38:30CheckBox和RadioButton控件都只有选中和未选中状态,不同的是RadioButton是单选按钮,需要编制到一个RadioGroup中,同一时刻一个RadioGroup中只能有一个按钮处于选中状态。以下为CheckBox和RadioButton常用方法及... -
Android控件系列之RadioButton与RadioGroup使用方法 详细出处参考:...
2013-04-06 15:00:001、掌握在Android中如何建立RadioGroup和RadioButton 2、掌握RadioGroup的常用属性 3、理解RadioButton和CheckBox的区别 4、掌握RadioGroup选中状态变换的事件(监听器) RadioButton和CheckBox的区别: 1、... -
Five-People:常用控件及其属性(RadioButton,CheckBox,align,margin,padding)使用方法
2016-04-17 17:02:057.控件背景与边框的设置(drawable中定义) (1)定义背景图(通过background间接引用drawable中的图片;实现时间被点击与未被点击时的不同背景) 演示: android :layout_width= ... -
Android基础控件单选按钮RadioButton和Checkbox复选按钮的使用
2017-12-21 15:46:00RadioButton需要和RadioGroup结合使用,在RadioGroup设置布局方式! Checkbox是单独使用,本文为了方便放在了RadioGroup中! 2、简单使用 方法说明: final RadioGroup radioGroup = (RadioGroup)... -
Activity常用控件二——RadioGroup、RadioButton、CheckBox的使用
2012-11-06 20:18:16这里主要简单的介绍了RadioGroup中的RadioButton和CheckBox的创建方法和监听器的设置 需要注意的是:RadioGroup的监听器和Button控件的监听器有所不同,分别为: RadioGroup.OnCheckedChangeListener ... -
Android控件之CheckBox、RadioButton探究
2011-02-21 21:20:00CheckBox和RadioButton控件都只有选中和未选中状态,不同的是RadioButton是单选按钮,需要编制到一个RadioGroup中,同一时刻一个RadioGroup中只能有一个按钮处于选中状态。 以下为CheckBox和RadioButton常用方法及... -
UltraWebGrid控件增加radiobutton单选按钮
2010-10-01 14:30:00UltraWebGrid控件增加radiobutton单选按钮,UltraWebGrid控件模板列的使用及数据的绑定方法
收藏数
350
精华内容
140