2016-03-27 21 views
0

我已创建两个单选按钮:Java的Android的 - 单选按钮没有显示

  • 首先,蓝牙
  • 其次,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); 
+0

请同时分享您的布局xml! – KostasC

+0

对不起,但我没有XML。目标是在alertdialog中添加两个RadioButton。当用户点击项目菜单时,会显示alertdialog。 – McNavy

回答

0

使用此代码来定义你的警告对话框。 Creatre包含两个单选按钮的xml布局,然后在java中使您的警报对话框中的视图和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(); 
+1

感谢您的帮助。我将在布局目录中创建一个新的XML文件。我会看到,如果它工作。 – McNavy