2016-03-27 20 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