android - 如何在 AlertDialog 框中添加两个编辑文本字段或 View ?

标签 android views android-edittext android-alertdialog

我想在警告对话框中添加两个编辑文本字段。尽管解决方案听起来很简单,但我至今仍无法收集到有效的解决方案。我无法同时设置两个(编辑文本) View 。

如果您想查看更多代码,请发表评论。

                alertDialog.setTitle("Values");
                final EditText quantity = new EditText(SecondScan.this);
                final EditText lot = new EditText(SecondScan.this);

                quantity.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
                lot.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);

                Project=arr[0].toString();
                Item=arr[1].toString();


                alertDialog.setMessage( "Employee No. : " + (Login.user).trim()+
                        "\nWarehouse      : " + (FirstScan.Warehouse).trim()+ 
                        "\nLocation           : " + (FirstScan.Location).trim()+ 
                        "\nProject              : " + Project.trim() + 
                        "\nItem                   : " + Item.trim() + 
                        "\nLot                      : " + Lot.trim()+  
                        "\n\nQuantity   :" );
                alertDialog.setView(quantity);
                    alertDialog.setView(lot);
 // the bit of code that doesn't seem to be working.


                alertDialog.setCancelable(false);
                alertDialog.setPositiveButton("Update",  new DialogInterface.OnClickListener() { 

                    public void onClick(DialogInterface dialog, int id) {
                        //ACTION
                    }
                });

                AlertDialog alert = alertDialog.create();
                alert.show();

我希望第一个编辑文本出现在 lot 之后,第二个编辑文本出现在 quantity 之后,而当我尝试将两者都插入时,似乎只有其中一个在工作观点。

更新:事实证明,实际上没有一种方法可以在不为其创建布局的情况下将多个 View 单独添加到警报对话框。

最佳答案

参见 Creating a Custom Layout在安卓中。

enter image description here

编辑

alertDialog.setTitle("Values");
final EditText quantity = new EditText(SecondScan.this);
final EditText lot = new EditText(SecondScan.this);

quantity.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
lot.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);

Project=arr[0].toString();
Item=arr[1].toString();

LinearLayout ll=new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(quantity);
ll.addView(lot);
alertDialog.setView(ll);

alertDialog.setCancelable(false);
alertDialog.setPositiveButton("Update",  new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
        //ACTION
    }
});

AlertDialog alert = alertDialog.create();
alert.show();

关于android - 如何在 AlertDialog 框中添加两个编辑文本字段或 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16169787/

相关文章:

iphone - 似乎没有加载带有 nib 作为 subview 的自定义 View

Android TableLayout 通过单击按钮添加来自 EditText 的数据的新行

android - 如何在 EditText 上启用默认复制粘贴

Android - 更改 READ_PHONE_STATE 权限请求消息

android - 在基于 Android 的嵌入式设备上使用 Google OAuth 2

android - 保存以编程方式添加的方向更改 View ?

Grails 3限制索引 View 中的列

android - 如何在 Android 的 EditText 中验证 URL/网站名称?

Android 处理程序消息和 ListView

android - 自 2.0 更新以来无法在 android studio 模拟器中启动应用程序