作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想在警告对话框中添加两个编辑文本字段。尽管解决方案听起来很简单,但我至今仍无法收集到有效的解决方案。我无法同时设置两个(编辑文本) 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在安卓中。
编辑
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/
我是一名优秀的程序员,十分优秀!