1

In my application, I am using the below passwordTransformationClass for showing the password in asterisk format. The problem is, I want a space after each text in the edit text, i.e. a space after every asterisk. But the overridden methods don’t take space except a single asterisk character.

public class AsteriskPasswordTransformationMethod 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
        }
    }
}
6
  • have you gone through Editext.addTextChangedListener. Commented Jul 5, 2016 at 7:48
  • @HimanshuMori- Let me try that, thank you. Commented Jul 5, 2016 at 7:53
  • Do you want spaces just for a visual effect??? In that case use letterSpacing Commented Jul 5, 2016 at 7:59
  • Actually letterSpacing not supported. Commented Jul 5, 2016 at 8:40
  • @Himanshu Mori- TextChangedListener not working Commented Jul 5, 2016 at 10:11

2 Answers 2

1

Input : <*****>

I hope this is your input in EditTextView and you want to transform the EditTextView text to something like

Output: <* * * * *>

then set some custom EditTextView fonts which have much spacing between characters...

Change font for EditText in Android?

and if you are going through Editext.addTextChangedListener, we can do it but we have to write down some expensive Logics into it to handle copy, paste, backspace and so many other cases .. :)

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your reply. Can you please recommend any font with spaces between characters so that I can test it out?@Himanshu Mori
my designer knows these fonts fontzone.net/font-details/oratorstd
-1

Try to change the code from

        public char charAt(int index)
        {
            return '*'; // This is the important part
        }

to

        public string charAt(int index)
        {
            return "* "; // This is the important part
        }

2 Comments

@Tony- tried that. Its showing error there. It doesn't take more than 1 character.
@AnimeshJena have you tried to take the transformed text and modify it with spaces between asterisks? after you have transformed it to asterisks..then put a space between each asterisk

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.