Android – ny widget for password entry

androidfieldpasswords

I was tryin to find any class to define a password field?
How can we do that?
Do we have a class for that or some method to edittext?

Best Answer

There are a couple of ways of doing this.

The first (apparently) deprecated, is to set this property on the widget in your layout resource file

android:password="true"

From code this is equivalent to calling:

myEditTextWidget.setTransformationMethod(new PasswordTransformationMethod());

(note that this also gives you the flexibility to supply your own implementation of the TransformationMethod interface).

The second mechanism is to set this property:

android:inputType="textPassword"

again, equivalent to calling:

myEditTextWidget.setInputType(InputType.TYPE_CLASS_TEXT |
                              InputType.TYPE_TEXT_VARIATION_PASSWORD);