0

I have four EditTexts for password and when I enter the value it automatically moves to the next edittext. I am following the How to change the focus to next edit text in android? , its working fine but after entering the digit in second text it is not changing as password , It displays like digit untill i touch the EditText field. I have set android:inputType="numberPassword".
But it is showing the digit and when I touch the screen or when I back press all the fields display as password, it works as password.
But before touching or back pressing the edit text field it always displays the digit.
My requirement is that when I enter it it should display characters as password not digits, but before backpressing it displays as digits.
Please guide me.

where my xml is for one EditText is given below and there is four edit text.

<EditText
  android:id="@+id/cnf_pin_first_edittext"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:contentDescription="@string/pin_content_desc"
  android:inputType="numberPassword"
  android:layout_marginRight="5dp"
 android:layout_marginLeft="5dp         android:background="@drawable/text_box_underline_selector"
 android:textColor="@color/black" />

and my code for three Edit text is given below

 final StringBuilder sbForFirstText = new StringBuilder();
    setPinFirstDigitEditText.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub
            if (sbForFirstText.length() == 0 & setPinFirstDigitEditText.length() == 1) {
                sbForFirstText.append(s);
                setPinFirstDigitEditText.clearFocus();
                setPinSecondDigitEditText.requestFocus();
                setPinSecondDigitEditText.setCursorVisible(true);
            }
        }
        public void beforeTextChanged(CharSequence s, int start, int count,
                                      int after) {
            if (sbForFirstText.length() == 1) {
                sbForFirstText.deleteCharAt(0);
            }
        }
        public void afterTextChanged(Editable s) {
            if (sbForFirstText.length() == 0) {
                setPinFirstDigitEditText.requestFocus();
            }
        }
    });

    final StringBuilder sbSecondText = new StringBuilder();
    setPinSecondDigitEditText.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub
            if (sbSecondText.length() == 0 & setPinSecondDigitEditText.length() == 1) {
                sbSecondText.append(s);
                setPinSecondDigitEditText.clearFocus();
                setPinThirdDigitEditText.requestFocus();
                setPinThirdDigitEditText.setCursorVisible(true);
            }
        }
        public void beforeTextChanged(CharSequence s, int start, int count,
                                      int after) {
            if (sbSecondText.length() == 1) {
                sbSecondText.deleteCharAt(0);
            }
        }
        public void afterTextChanged(Editable s) {
            if (sbSecondText.length() == 0) {
                setPinSecondDigitEditText.requestFocus();

            }
        }
    });

    final StringBuilder sbThirdText = new StringBuilder();
    setPinThirdDigitEditText.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub
            if (sbThirdText.length() == 0 & setPinThirdDigitEditText.length() == 1) {
                sbThirdText.append(s);
                setPinThirdDigitEditText.clearFocus();
                setPinForthDigitEditText.requestFocus();
                setPinForthDigitEditText.setCursorVisible(true);
            }
        }
        public void beforeTextChanged(CharSequence s, int start, int count,
                                      int after) {
            if (sbThirdText.length() == 1) {
                sbThirdText.deleteCharAt(0);
            }
        }
        public void afterTextChanged(Editable s) {
            if (sbThirdText.length() == 0) {
                setPinThirdDigitEditText.requestFocus();
            }
        }
    });
Gyan S Awasthi
  • 237
  • 6
  • 14

1 Answers1

0

Set android:inputType="textPassword"

Tara
  • 692
  • 5
  • 23