Java Android - Radio Button没有显示

时间:2016-03-27 15:15:24

标签: java android radio-button

我创建了两个单选按钮:

  • 首先,对于蓝牙
  • 其次,对于RS232

但我的应用程序只显示其中一个。

这是我的代码:

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

1 个答案:

答案 0 :(得分:0)

使用此代码定义警报对话框。 创建一个包含两个单选按钮的xml布局,然后在警报对话框中的java make view和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();