简体   繁体   English

Java Android-单选按钮未显示

[英]Java Android - Radio Button not showing

I have create two radio buttons: 我创建了两个单选按钮:

  • First, for Bluetooth 首先,对于蓝牙
  • Second, for RS232 二,针对RS232

But my application shows only one of them. 但是我的应用程序仅显示其中之一。

This is my code : 这是我的代码:

final RadioButton Bluetooth = new RadioButton(this);
Bluetooth.setId(TEXT_ID);
alertDialogBuilder.setView(Bluetooth);
Bluetooth.setText("Bluetooth");
Bluetooth.setTextSize(20);

final RadioButton RS232 = new RadioButton(this);
RS232.setId(TEXT_ID);
alertDialogBuilder.setView(RS232);
RS232.setText("RS232");
RS232.setTextSize(20);

Use this code to define your alert dialog. 使用此代码定义警报对话框。 Creatre aa xml layout containing two radio buttons and then in java make view and inflathat view in your alert dialog. 创建一个包含两个单选按钮的xml布局,然后在Java中的警报对话框中使用make视图和inflathat视图。

                View view2 = View.inflate(MyActivity.this, R.layout.radiobutton, null);

                AlertDialog.Builder builderconversion = new AlertDialog.Builder(MyActivity.this);
                //builder1.setMessage("Radio Message");
                builderconversion.setView(view2);
                builderconversion.setCancelable(true);
                builderconversion.setPositiveButton("CLOSE",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {

                                //Methods and functions
                                dialog.cancel();
                            }
                        });

                AlertDialog alertconversion = builderconversion.create();
                alertconversion.show();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM