androidandroid-edittextandroid-inputtype

Set inputType for an EditText Programmatically?


How do we set the input type for an EditText programatically? I'm trying:

mEdit.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);

it doesn't seem to have any effect.


Solution

  • According to the TextView docs, the programmatic version of android:password is setTransformationMethod(), not setInputType(). So something like:

    mEdit.setTransformationMethod(PasswordTransformationMethod.getInstance());
    

    should do the trick.