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.
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.
Try adding this to the EditText/TextView tag in your layout
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.
To only allow numbers:
To transform (hide) the password:
I know the expected Answer is in
Java
. But here's my 2 cents of advice always try to handle view related stuff inXML
(atleast basic stuff) so I would suggest rather use axml
attribute rather than handling this use case injava
//you can change TYPE_... according to your requirement.
This may be of help to others like me who wanted to toggle between password and free-text mode. I tried using the input methods suggested but it only worked in one direction. I could go from password to text but then I could not revert. For those trying to handle a toggle (eg a show Password check box) use
I have to credit this for the solution. Wish I had found that a few hours ago!
According to the TextView docs, the programmatic version of android:password is setTransformationMethod(), not setInputType(). So something like:
should do the trick.