Adding Edittext To Alert Dialog.
I have the following code that create alert dialog and I added two edit text to it but once I run the app the values within the EditText won't be retrived and my app crash with Nul
Solution 1:
Thanks guys for your contributions in answering my question, and I think I got the solution for the problem that I posted above which is:
AlertDialog.Builderalert=newAlertDialog.Builder(MyFeedActivity.this);
LayoutInflater inflater=MyFeedActivity.this.getLayoutInflater();
//this is what I did to added the layout to the alert dialog
View layout=inflater.inflate(R.layout.dialog,null);
alert.setView(layout);
final EditText usernameInput=(EditText)layout.findViewById(R.id.dialogusername);
final EditText passwordInput=(EditText)layout.findViewById(R.id.dialogpassword);
and I think the problem was that I cannot get the EidtText within the alert dialog, but by doing it by the above code every thing works just fine with me.
Solution 2:
use this:
finalAlertDialogalertDialog=newAlertDialog.Builder(this).create();
finalEditTextinput=newEditText(this);
input.setHint("hint");
alertDialog.setTitle("title");
alertDialog.setMessage(message);
alertDialog.setView(input);
Solution 3:
Try editing like this
final EditText usernameInput=(EditText)this.findViewById(R.id.dialogusername);
final EditText passwordInput=(EditText)this.findViewById(R.id.dialogpassword);
OR
final EditText usernameInput=(EditText)alert.findViewById(R.id.dialogusername);
final EditText passwordInput=(EditText)alert.findViewById(R.id.dialogpassword);
Post a Comment for "Adding Edittext To Alert Dialog."