Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edittext input type password, not hiding text after clear focus android

Tags:

I am using a view to enter user's four digit PIN. the UI consists of 4 edittext each having maxLength set to 1. On entering value to edit text1, focus is then shifted to the second edittext and so on. each Edittext input type is : numberPassword.

<EditText
            android:id="@+id/ed_1"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:gravity="center"
            android:inputType="numberPassword"
            android:maxLength="1" />

In java, to shift the focus, we have applied following text watcher to each of the edittext:

ed1.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.toString().length() == 1) {
                ed1.clearFocus();
                ed2.requestFocus();
                ed2.setCursorVisible(true);
            }
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

Problem is, value of edittext are not changing to *, it shows the real input number (not changing to password). Only 1st and last are changing to *, where as center two that means edittext 2 and edittext 3 are still have visible passwords.

Right now: We have 4 input Edittexts

desired output should be: | * | * | * | * |

When we fill the values, and switches the focus, by using java code specified, they get change to: (input value: 1234): | * | 2 | 3 | * |

If we focus back on either of the center edit texts, then value changes to password. Is it because of removing focus, and the transformation time required to change a field to password takes more time? Is there any method with which we can forcefully change the value to password.

like image 370
user3099103 Avatar asked Sep 15 '17 05:09

user3099103


People also ask

How did the developer hide the input by dots in the password EditText?

change the edittext input type property to text password in xml. Show activity on this post. As the original poster mentioned in a comment, calling setSingleLine (boolean singleLine) resets the EditText settings, so you'll have to call that first and after that set custom settings like the password InputType .

How do I change my hide and view password?

setTransformationMethod(new PasswordTransformationMethod()); to hide the password. To show the password you could set one of the existing transformation methods or implement an empty TransformationMethod that does nothing with the input text. To show the password, you don't need to make any new classes.


1 Answers

Try running the following code for the previous text after the transitions

yourEditText.setTransformationMethod(new PasswordTransformationMethod());

it's a difficult method but

String e1,e2,e3,e4; 
@Override 
public void onTextChanged(CharSequence s, int start, int before, int count) { 
if (s.toString().length() == 1 && !ed1.getText().toString().equals("*")) { 
e1=ed1.getText(); 
ed1.setText("*"); 
ed2.requestFocus(); 
ed2.setCursorVisible(true); } }

you can use this method

like image 87
UMKalaycı Avatar answered Sep 24 '22 10:09

UMKalaycı