2014-09-20 46 views
1

我想創建一個對話框警報,因爲它顯示在android中,當我們點擊一​​個Wi-Fi連接到Wi-Fi時。我創建了一個對話框提示,但沒有顯示所有的textview和edittext。請幫助如何在對話框警報中添加多個文本視圖和編輯文本

這裏是我的代碼

AlertDialog.Builder password = new AlertDialog.Builder(context); 
     password.setTitle("Connect to Network"); 

     final TextView ssid = new TextView(context); 
     ssid.setText(wifiScanList.get(position).SSID); 
     password.setView(ssid); 
     final TextView bssid=new TextView(context); 
     bssid.setText(wifiScanList.get(position).BSSID); 
     password.setView(bssid); 
     final TextView capab=new TextView(context); 
     capab.setText(wifiScanList.get(position).capabilities); 
     password.setView(capab); 
     final EditText pass =new EditText(context); 
     password.setView(pass);  

     password.setPositiveButton("Connect", new DialogInterface.OnClickListener() { 

      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       // TODO Auto-generated method stub 
       checkPassword= pass.getText().toString(); 
       finallyConnect(checkPassword, position); 
       dialog.dismiss(); 


      } 
     }); 
     password.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 

      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       // TODO Auto-generated method stub 

       dialog.cancel(); 
      } 
     }); 
     AlertDialog passdialog = password.create(); 
     passdialog.show(); 
+0

請發表意見xml代碼 – 2014-09-20 10:35:32

+0

@rogerthatcode我沒有使用xml代碼來創建對話框警報。 – user3853169 2014-09-20 10:42:14

回答

0

最好的辦法是設計在單獨的XML文件自定義對話框讓我們說

customdialog.xml在R /佈局文件夾

並從您的活動中,您可以創建一個新的AlertDialog,並將它應用於此主題

// Create custom dialog object 
       final Dialog dialog = new Dialog(this); 
       dialog.setContentView(R.layout.customdialog); 
       // Set dialog title 
       dialog.setTitle("Custom Dialog"); 
       // here you can get the reference to your Views and do whatever you want with 
+1

但我想在按鈕,因爲我們在alerdialog和使用XML我無法啓用這些按鈕。你能告訴我如何在XML中添加這些按鈕 – user3853169 2014-09-20 10:44:29

相關問題