0

I am trying to use the android:inputType="numberPassword" and it is not working. The numbers still appear in the EditText. This only happens when I add TextWatcher to switch to next EditText after entering in the first.

public void onTextChanged(CharSequence s, int start, int before, int count) {
        // TODO Auto-generated method stub
        if (ps1.getText().hashCode() == s.hashCode()) {
            ps1.clearFocus();
            ps2.requestFocus();
            ps2.setCursorVisible(true);
        } else if (ps2.getText().hashCode() == s.hashCode()) {
            ps2.clearFocus();
            ps3.requestFocus();
            ps3.setCursorVisible(true);
        } else if (ps3.getText().hashCode() == s.hashCode()) {
            ps3.clearFocus();
            ps4.requestFocus();
            ps4.setCursorVisible(true);
        }
    }

What can I do to make this work properly?

Cœur
  • 37,241
  • 25
  • 195
  • 267
vishalmullur
  • 1,094
  • 4
  • 14
  • 32

5 Answers5

1
This problem can be solved without using deprecated android:password. Use the following code snippet, but do not reverse the sequence of calls:

    EditText editText = (EditText) findViewById(R.id.MyEditText);
    editText.setInputType(InputType.TYPE_CLASS_NUMBER);
    editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
krunal patel
  • 2,369
  • 1
  • 11
  • 11
1

use below line in your xml file hope it will help you

android:password="true"

may be it is deprecated but it will solve your problem just try it

or you can try

android:inputType="textPassword|number" 

ignore textPassword and only accept number but not password.

So you should use android:inputType="textPassword|number" with android:password="true".

that seems to be the only solution.

1

Just write your Edit-texts in your XML like following.

<EditText
                android:id="@+id/ed_login_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:inputType="textPassword"
                android:singleLine="true"
                android:text=""
/>

OR

Try out with programmatically setinputtype to the Edittext.

editPass.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD)

I think their is an problem in your Textwatcher so if you want to use Single TextWatcher for multiple EditTexts.

Look into the following link:-How to use Single TextWatcher for multiple EditTexts?

OR

Access your Editexts in the following method of TextWatcher

public void afterTextChanged(Editable editable) {

 }

Hope it will helps you.

Community
  • 1
  • 1
Born To Win
  • 3,319
  • 3
  • 19
  • 27
0

If anyone is looking for the answer its simple. Let your EditText have this line android:inputType="numberPassword". No need to use the depreciated things. Just put the code in afterTextChanged instead of onTextChanged.

 @Override
    public void afterTextChanged(Editable s) {
        // TODO Auto-generated method stub
        if (ps1.getText().hashCode() == s.hashCode()) {
            ps1.clearFocus();
            ps2.requestFocus();
            ps2.setCursorVisible(true);
        } else if (ps2.getText().hashCode() == s.hashCode()) {
            ps2.clearFocus();
            ps3.requestFocus();
            ps3.setCursorVisible(true);
        } else if (ps3.getText().hashCode() == s.hashCode()) {
            ps3.clearFocus();
            ps4.requestFocus();
            ps4.setCursorVisible(true);
        }
    }

I am not sure why this works so anyone who knows may please explain.

vishalmullur
  • 1,094
  • 4
  • 14
  • 32
0

for me android:inputType="numberPassword" works for ValidationEditText

Neelam Verma
  • 3,232
  • 1
  • 22
  • 33