我想创建一个EditText
接受密码的。我想在输入字符后立即隐藏它。所以,我用了一个TransformationMethod
. 我是新手,所以我尝试了以下代码。
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);
}
}
然而,它抛出,
01-03 10:22:35.750: E/AndroidRuntime(2102): java.lang.IndexOutOfBoundsException
我错过了一些东西。任何帮助将不胜感激。