I am trying to show an alert with two edittext fields in Android. The source is as follows:
public void UserPass(){
final SharedPreferences prefs=getSharedPreferences("PrefsPreferences",MODE_PRIVATE);
String user=prefs.getString("user", "");
String pass=prefs.getString("password", "");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("U/P");
builder.setCancelable(false);
final EditText input1 = new EditText(this);
final EditText input2 = new EditText(this);
builder.setView(input1);
builder.setView(input2);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//My code
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
Only one EditText is showing up. What am I doing wrong?
Thanks!
The second
setViewcall replaces theEditTextyou set in the first. You can’t add twoViews this way. Instead, create aLinearLayout, add bothinput1andinput2to that, and then add that to thebuilder.