Is there a clever way to let the user switch between hide and view password in an android EditText? A number of PC based apps let the user do this.
+1
A:
You can dynamically change the attributes of a TextView. If you would set the XML Atrribute android:password
to true the view would show dots if you set it to false the text is shown.
With the method setTransformationMethod you should be able to change this attributes from code. (Disclaimer: I have not tested if the method still works after the view is displayed. If you encounter problems with that leave me a comment for me to know.)
The full sample code would be
yourTextView.setTransformationMode(new PasswordTransformationMethod());
to hide the password. To show the password you could set one of the existing transformation methods or implement an empty TransformationMethod that does nothing with the input text.
yourTextView.setTransformationMode(new DoNothingTransformation());
Janusz
2010-09-10 15:19:56
Thanks. yourTextView.setTransformationMethod(new PasswordTransformationMethod()); Does exactly what I need. I also have not tested if the method still works after the view is displayed.
JackN
2010-09-10 18:09:36