0

in my app I have to disabled EditText and changing text in EditText programatically, problem is I want EditText to listen for TextWatcher which I added on EditText.

But EditText is not listening watcher.

So can anyone please help to enable EditText listen for TextWatcher while it is disabled and text is populated to EditText programatically not through KeyBoard.

I tried the below code

txtShift.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {


        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
            if (s.length()>0) {
                keyPadOnOff(false);
            }else {
                keyPadOnOff(true);

            }       
        }
    });

thanks

Neha Shukla
  • 3,572
  • 5
  • 38
  • 69

3 Answers3

0

Check the followings

  1. Are you import this line ?- import android.text.TextWatcher;
  2. Are you Initialize the EditText properly?
  3. Set a Log.v on method - afterTextChanged(Editable s) and check it first.

    public void afterTextChanged(Editable s) {

    Log.v(TAG,"AfterTextChanged worked");

    }

  4. If the 3rd point correctly get Log values. The error is in the method keyPadOnOff(boolean)

5.Check the method keyPadOnOff(boolean).

Venkatesh Selvam
  • 1,382
  • 2
  • 15
  • 28
0

after so much digging at Google I found we are unable to make EditText listen for watcher if it made

et.setFocusable(false);
et.setClickable(false);

So what I did, I trigger the event when I am populating text in EditText from my code.

Neha Shukla
  • 3,572
  • 5
  • 38
  • 69
0

you can enable TextWatcher with this line:

txtShift.removeTextChangedListener(textWatcher);

you can start with:

txtShift.addTextChangedListener(textWatcher);

TextWatcher textWatcher = new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {

            if (s.length()>0) {
                keyPadOnOff(false);
            }else {
                keyPadOnOff(true);
            }

        }
    };
Cabezas
  • 9,329
  • 7
  • 67
  • 69