jak korzystać z TransformationMethod na Androida
Chcę stworzyćEditText
który akceptuje hasła. Chcę ukryć postać, gdy tylko zostanie wpisana. Więc użyłemTransformationMethod
. Jestem nowy w tym zakresie, więc wypróbowałem następujący kod.
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);
}
}
Jednak to rzuca,
01-03 10:22:35.750: E/AndroidRuntime(2102): java.lang.IndexOutOfBoundsException
Brakuje mi czegoś. Każda pomoc zostanie doceniona.