如何设置在Android的单选按钮 [英] How to set a radio button in Android

查看:194
本文介绍了如何设置在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文件我有:

final RadioButton radio1 = (RadioButton)findViewById(R.id.rb_sat1E);

我还创建了一个重置按钮,在主要的Java文件,可以使用下面的code重置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");

但是,这并不在所有的工作。

But that does not work at all.

任何帮助非常AP preciated。谢谢你。

Any help greatly appreciated. Thanks.

推荐答案

有关单选按钮使用

radio1.setChecked(true);

这是没有意义的只有一个单选按钮。如果您有更多的人需要通过取消选中其他

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); ...

如果您的设置仅仅是开/关使用复选框。

If your setting is just on/off use CheckBox.

这篇关于如何设置在Android的单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆