gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:31:45 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com