Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AlertDialog with EditText with InputType email - Android

I'm creating alert dialog with one EditText. I want that EditText to have input type email. This is my code:

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

alert.setMessage("Enter your email");

final EditText email = new EditText(this);
email.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
email.setHint("Email...");

alert.setView(email);

alert.setPositiveButton("Ok", null);

alert.setNegativeButton("Cancel", null);

alert.show();

I also set Hint to that EditText and it's work, but input type does't work.....Any suggestion?

like image 598
KiKo Avatar asked Mar 27 '14 16:03

KiKo


1 Answers

You have to add below code to make it work :

email.setInputType(InputType.TYPE_CLASS_TEXT 
          | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);

See InputType. TYPE_TEXT_VARIATION_EMAIL_ADDRESS is just a variation basically that you add to the TYPE_CLASS_TEXT flag. It somehow makes sense.

like image 80
Ovidiu Latcu Avatar answered Sep 25 '22 02:09

Ovidiu Latcu