views:

203

answers:

3

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?

+2  A: 

In the xml layout file try assigning this property to your edittext...

android:password="true"
Ryan
+5  A: 

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);
Alnitak
+2  A: 

Better to use the inputType property, the password one is now deprecated.

<EditText android:id="@+id/password" android:inputType="textPassword"/>

Mirko Nasato
Which SDK release deprecated it? 70% of Android devices are still running Android 1.6 or earlier.
Alnitak
And from code, that's setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD).
Mirko Nasato
Don't know when 'password' was deprecated, but inputType works at least since Android 1.5.
Mirko Nasato
thanks for the extra info - I've collated in my answer so it's all in one place.
Alnitak