0

Friends,

I m quite new so sorry for the basic question but after hours of searching I gave up. How do i add a second EditText to my AlertDialog? It shows just one Edittext with the two Buttons. The second EditText is not Displayed at all.

heres my code,

final AlertDialog.Builder alert = new AlertDialog.Builder(ctx);
final EditText inputstreet = new EditText(ctx);
final EditText inputstreetnumber = new EditText(ctx);

alert.setView(inputstreet);
alert.setView(inputstreetnumber);
               alert.setTitle(getResources().getString(R.string.t_MainAlertEnterAdressTitle));
// alert.setIcon(R.drawable.huji2); // Icon disabled for now
alert.setMessage(getResources().getString(R.string.t_MainAlertEnterAdressMessage));
alert.setPositiveButton(getResources().getString(R.string.t_MainAlertEnterAdressButtonOk),
        new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog,
                    int whichButton) {


                finish();
            }
        });

alert.setNegativeButton(getResources().getString(R.string.t_MainAlertEnterAdressButtonBack),
        new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog,
                    int whichButton) {

                dialog.cancel();

            }
        });
alert.show();

I removed everything whats not important. Thanks a lot!!!

Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
The Digital Ad Venture
  • 1,576
  • 1
  • 16
  • 24

1 Answers1

4

Your alert dialog can only hold one view, so you have to put your EditText views inside a single layout view, like this:

final AlertDialog.Builder alert = new AlertDialog.Builder(this);

final LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);

final EditText inputstreet = new EditText(this);
final EditText inputstreetnumber = new EditText(this);

layout.addView(inputstreet);
layout.addView(inputstreetnumber);

alert.setView(layout);
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
skynet
  • 9,898
  • 5
  • 43
  • 52
  • works amazing. Thanks a lot!!! you may know how i can change the input type of the keyboard of the EditText? – The Digital Ad Venture Oct 25 '11 at 20:04
  • If you want the user to be able to input numbers, look [here](http://stackoverflow.com/questions/1119583/how-do-i-show-the-number-keyboard-on-an-edittext-in-android). Otherwise please post a new question – skynet Oct 25 '11 at 20:36