afterTextChanged() callback being called without the text being actually changed

非 Y 不嫁゛ 提交于 2019-12-01 14:58:51

Edited solution:

As it seems the text was changed from the second time the fragment was attached because the fragment restored the previous state of the views.

My solution was adding the text watcher in the onResume() since the state was restored before the onResume was called.

@Override
public void onResume() {
    super.onResume();
    myEditText.addTextChangedListener(textWatcher);
}

Edit As @MiloszTylenda have mentioned in the comments it is better to remove the Textwatcher in the onPause() callback to avoid leaking the Textwatcher.

@Override public void onPause() {
  super.onPause();
  myEditText.removeTextChangedListener(watcher);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!