Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top