I want to create an EditText
which accepts passwords. I want to hide the character as soon as it is typed. So, I used a TransformationMethod
.
I am new to this so, I tried the following code.
EditText editText = (EditText) findViewById(R.id.editText);
editText.setTransformationMethod(new PasswordTransformationMethod());
private class PasswordTransformationMethod extends Transformation implements TransformationMethod {
@Override
public CharSequence getTransformation(CharSequence source, View view) {
return "/";
}
@Override
public void onFocusChanged(View view, CharSequence source, boolean focused, int direction, Rect previouslyFocusedRect) {
source = getTransformation(source, view);
}
}
However, it throws,
01-03 10:22:35.750: E/AndroidRuntime(2102): java.lang.IndexOutOfBoundsException
I am missing something. Any help will be appreciated.