How to set a radio button in Android(如何在 Android 中设置单选按钮)
问题描述
我有一个使用单选按钮的应用.此按钮的默认设置在 main.xml 文件中,即:
I have an app that uses radio buttons. The default for this button is set in the main.xml file, ie:
android:id="@+id/rb_sat1E"
android:checked="true"
在我拥有的 Java 文件中:
In the Java file I have:
final RadioButton radio1 = (RadioButton)findViewById(R.id.rb_sat1E);
我还在 Java 主文件中创建了一个重置"按钮,可以使用以下代码重置 TextView 信息,即.
I have also created a 'Reset' button in the main Java file and can use the following code to reset TextView information ie.
pos1_deg.setText("0.0");
但是如何重置单选按钮?我本来以为是这样的
But how do I reset a radio button? I would have thought it to be something like
radio1.setBoolean("TRUE");
但这根本不起作用.
非常感谢任何帮助.谢谢.
Any help greatly appreciated. Thanks.
推荐答案
供radioButton使用
For radioButton use
radio1.setChecked(true);
只有一个 RadioButton 是没有意义的.如果您有更多,则需要通过
It does not make sense to have just one RadioButton. If you have more of them you need to uncheck others through
radio2.setChecked(false); ...
如果您的设置只是开/关,请使用 CheckBox.
If your setting is just on/off use CheckBox.
这篇关于如何在 Android 中设置单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Android 中设置单选按钮
基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
