0

Edit text for OTP with Each letter in separate positions

In Android above mentioned link have already given the correct answer but "android:inputType=numberPassword" is not working and the cursor is not showing up.

anyhow I managed to show start instead of numbers using the below code

private String convertToStar(){
        Editable editable = getText();
        Helper.v("OTPEditText","OTP getText["+editable.toString()+"]");
        StringBuilder retStr = new StringBuilder();
        int i=0;

        while(i<editable.length()){
            retStr.append("*");
            i++;
        }
        return retStr.toString();
    }

But still cursor is not visible. Any help?

1 Answers1

1

The custom view that you are using does all of its own drawing of the input field. As you have already determined, you need to change the code to draw the asterisks to hide the characters that are input.

Unfortunately, the blinking cursor is part of the EditText code that is not replicated in your custom view. See here for how the cursor is implemented. Implementation of the cursor is surprisingly complicated and you would need to do something similar. (It is doable but not a happy prospect.)

The Stack Overflow question from where you copied your custom view code has another answer (the accepted answer) that seems to do all that you want to do. See here. I recommend that you take a look at implementing this approach.

Cheticamp
  • 61,413
  • 10
  • 78
  • 131