tags:

views:

68

answers:

2

Hi,

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.

Thanks

A: 

Try adding this to the EditText/TextView tag in your layout

android:password="true"

Edit: I just re-read your post, perhaps you need to do this after construction. I don't see why your snippet wouldn't work.

Jim Blackler
I don't have a layout file in this case, the fields are being generated programatically.
Yeah it is being done after construction, not sure why it's not working either!
+1  A: 

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.

rascalking