JAVA-已选中RadioButton

JAVA-已选中RadioButton,java,android,radio-button,Java,Android,Radio Button,我的申请有一个问题。我有两个单选按钮: <RadioGroup android:layout_width="148dp" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" > <!-- android:buttonTint="@color/BouttonsRadio" --> <RadioButton an

我的申请有一个问题。我有两个
单选按钮

<RadioGroup
    android:layout_width="148dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal" >
<!-- android:buttonTint="@color/BouttonsRadio" --> 

    <RadioButton
        android:layout_width="137dp"
        android:layout_height="wrap_content"
        android:text="@string/Boutton_Bluetooth"
        android:id="@+id/BouttonRADIO_Bluetooth"
        android:layout_gravity="center_horizontal"
        android:textSize="20dp"
        android:textStyle="bold" />

    <RadioButton
        android:layout_width="137dp"
        android:layout_height="wrap_content"
        android:text="@string/Boutton_RS232"
        android:id="@+id/BouttonRADIO_RS232"
        android:layout_gravity="center_horizontal"
        android:textSize="20dp"
        android:textStyle="bold" />
</RadioGroup>
最后,我将要检索选中的单选按钮,并且只有当它是蓝牙时,才禁用空档
按钮
。 为此,我找到了这个,但不起作用:

Button button = alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL);

if(BouttonRadio_B.isChecked()) {
    button.setEnabled(false);
}
if(BouttonRadio_R.isChecked()) {
    button.setEnabled(true);
}
这是必须的

    Button button = alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL);
    if(BouttonRadio_B.isChecked()) {
        button.setEnabled(false);
    }
    if(BouttonRadio_R.isChecked()) {
        button.setEnabled(true);
    }
显示对话后是否执行此代码

alertDialog.show();
这是必须的

    Button button = alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL);
    if(BouttonRadio_B.isChecked()) {
        button.setEnabled(false);
    }
    if(BouttonRadio_R.isChecked()) {
        button.setEnabled(true);
    }
显示对话后是否执行此代码

alertDialog.show();

您必须实现侦听器来侦听
单选按钮的check change listener
。有关更多详细信息,请参阅。是的,您可以使用
按钮。设置已启用(isChecked)


这应该适合您。

您必须实现侦听器来侦听
单选按钮的检查更改侦听器。有关更多详细信息,请参阅。是的,您可以使用
按钮。设置已启用(isChecked)


这应该对您有用。

您在哪一类和方法中拥有上一节中提供的代码,用于获取对话框按钮,检查是否选中单选按钮(两个按钮中的任何一个),然后启用/禁用对话框按钮remote@nits.kk:我的类是MainActivity.java,我的方法在Mainactivity中。在哪个类和方法中有上一节中提供的代码,用于获取对话框的按钮,检查是否选中了单选按钮(两个中的任何一个),然后启用/禁用对话框的按钮remote@nits.kk:我的类是MainActivity.java,我的方法是在Mainactivity中。克鲁米什:我对你的代码没意见。我在alerttdialog.show()之后添加此代码。应用程序编译没有错误,但是当我点击菜单上的项目时,谁使用了这个方法,应用程序FC.Krumish:我对你的代码没意见。我在alerttdialog.show()之后添加此代码。应用程序编译没有错误,但当我单击菜单上的项目时,谁使用了此方法,即应用程序FC。请在您的回答中指出为什么这是解决问题的好方法?另外,您是否可以只执行
按钮.setEnabled(isChecked)
这将保存if/else结构。您必须实现侦听器才能侦听RadioButton的检查更改侦听器。有关更多详细信息,请参阅。是的,您可以使用button.setEnabled(isChecked)。如果有帮助,请向上投票。谢谢。我已经为你编辑好了,请以后自己做吧<代码>:-)
您能在回答中指出为什么这是解决问题的好方法吗?另外,您是否可以只执行
按钮.setEnabled(isChecked)
这将保存if/else结构。您必须实现侦听器才能侦听RadioButton的检查更改侦听器。有关更多详细信息,请参阅。是的,您可以使用button.setEnabled(isChecked)。如果有帮助,请向上投票。谢谢。我已经为你编辑好了,请以后自己做吧<代码>:-)