-3

I have a requirement in which when the user enters a text in an EditText it should display asterisk/dot. I have tried using inputType as textPassword. If I use the inputType, first it will display the character, and then change to asterisk/dot. What I need is the character should not be displayed and it should show only the asterisk/dot.

Can someone please help me to achieve this?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
somia
  • 611
  • 5
  • 22
  • use like this https://stackoverflow.com/a/38989021/6666677 – Bhavesh Desai Nov 01 '17 at 10:12
  • 3
    Possible duplicate of [Android: How to set password property in an edit text?](https://stackoverflow.com/questions/6094962/android-how-to-set-password-property-in-an-edit-text) – Robbe Nov 01 '17 at 10:15
  • Possible duplicate of [Change EditText password mask character to asterisk (\*)](https://stackoverflow.com/questions/14051962/change-edittext-password-mask-character-to-asterisk) – Swarup Rajbhandari Oct 26 '18 at 08:00

1 Answers1

1

try below code

editText.setTransformationMethod(new PasswordTransformationMethod());


public class PasswordTransformationMethod extends PasswordTransformationMethod {
@Override
public CharSequence getTransformation(CharSequence source, View view) {
    return new PasswordCharSequence(source);
}

private class PasswordCharSequence implements CharSequence {
    private CharSequence mSource;
    public PasswordCharSequence(CharSequence source) {
        mSource = source; // Store char sequence
    }
    public char charAt(int index) {
        return '*'; // This is the important part
    }
    public int length() {
        return mSource.length(); // Return default
    }
    public CharSequence subSequence(int start, int end) {
        return mSource.subSequence(start, end); // Return default
    }
}

};

Munir
  • 2,548
  • 1
  • 11
  • 20