Hi devs,
Introduction
Most of us developers may be hung up in a never ending loop causing StackOverflow Exception when changing the content of EditText inside its own textChangeListener.
How to change the text of an EditText inside the EditText addTextChangeListener in Android?
Hope you solve the frustrating problem with this simple trick.And share your ideas through comment box.
Introduction
Most of us developers may be hung up in a never ending loop causing StackOverflow Exception when changing the content of EditText inside its own textChangeListener.
How to change the text of an EditText inside the EditText addTextChangeListener in Android?
//First initialize the EditText and addTextChangedListener like shown below.
editText1.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) {}
@Override
public void afterTextChanged(Editable s) {
//Before changing the text inside the EditText you want to remove the text change listener.
editText1.removeTextChangedListener(this);
//Here you make the changes to EditText
editText1.setText("hi");
//After changing the content of the EditText you want to register the text change listener.
editText1.addTextChangedListener(this);
}
});
Hope you solve the frustrating problem with this simple trick.And share your ideas through comment box.
0 comments:
Post a Comment
Don't be shy. Just leave your comments, am so happy to assist you. And, don't forgot that I am such a nice person who you are dealing with :)