如何在对话框警报中添加多个文本视图和编辑文本

时间:2014-09-20 10:30:30

标签: android dialog android-edittext textview

我想创建一个对话框警报,因为当我们点击一​​个Wi-Fi连接到Wi-Fi时它会显示在android中。我创建了一个对话框警报,但它没有显示所有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();

1 个答案:

答案 0 :(得分:0)

最好的方法是在一个单独的xml文件中设计自定义对话框,让我们说

  

R / layout文件夹中的customdialog.xml

从您的Activity中,您可以创建一个新的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