Garima Tiwari Garima Tiwari - 4 months ago 15
Android Question

How to add two edit text fields or views in an AlertDialog box?

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.

UPDATE : As it turns out there is in fact no method of adding more than one view alone to an alert dialog box without having to create a layout for it.

TCA TCA
Answer

See Creating a Custom Layout in android.

enter image description here

EDIT

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