如何在AlertDialog框中添加两个编辑文本字段或视图? [英] How to add two edit text fields or views in an AlertDialog box?

查看:152
本文介绍了如何在AlertDialog框中添加两个编辑文本字段或视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在警报对话框中添加两个编辑文本字段.解决方案听起来很简单,但到目前为止我还无法收集到一个可行的解决方案.我无法同时设置两个(编辑文本)视图.

I want to add two edit text fields in an alert dialog box. As simple as the solution sounds I have not been able to gather a working one as of yet. I am not able to set the two (edit text) views simultaneously.

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

Please comment in case you want to see any further code.

                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();

我希望第一个编辑文本出现在批号之后,第二个编辑文本出现在数量之后,而当我尝试同时推入两个文本时,似乎只有其中一个在起作用视图.

I want the first edit text to occur after the lot and the second one after the quantity whereas only one of them seems to be working when I try pushing in both the views.

更新:事实证明,实际上没有一种方法可以单独向警报对话框添加多个视图,而无需为其创建布局.

推荐答案

请参见在android中创建自定义布局.

编辑

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();

这篇关于如何在AlertDialog框中添加两个编辑文本字段或视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆