如何设置在Android的单选按钮单选、如何设置、按钮、Android

2023-09-06 01:32:50 作者:旧疤°

我有一个使用单选按钮的应用程序。默认此按钮将在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.