How to access the View that triggered one of the events of a Textwatcher?

Asked

Viewed 130 times

0

Explanation:

I have a common application where there are several components EditText, where I assign them an Handler that would be this one:

TextWatcher handler = 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) {
        oldText = s.toString();
    }

    @Override
    public void afterTextChanged(Editable s) {
        //v.setText("afterTextChanged");
    }
};

It is working ok, and the Debugger enters right, events are triggered, but I would like to have access to View that is firing the events to have access to the method .setText().

Question:

How to access the View that triggered an Handler event TextWatcher?

Exactly the same way v of the event onClick

1 answer

2


What you seek is value s passed to the function. If you change s the TextView will show this change.

Please note that any changes you make to s, the method afterTextChanged will be calling again, which will provoke a loop infinite.

Source Textwatcher

  • But I must change the s how? s = "aa" ?

  • Yes. Internally the Textview class uses a Editable(or something I inherit from Editable) to store its value. This is passed to the method afterTextChanged. When you invoke getText what returns is a Editable

Browser other questions tagged

You are not signed in. Login or sign up in order to post.