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

前端 未结 2 1055
Happy的楠姐
Happy的楠姐 2021-01-07 17:36

I have a fragment with an EditText and inside the onCreateView() I add a TextWatcher to the EditText.

Each time t

2条回答
  •  时光取名叫无心
    2021-01-07 18:04

    It seems that this error comes from the fact that Android SDK will call settext when view is coming alive again to recover the state of the EditText. As you can see from the extract below there is a flag that you can change on the Edittext to bypass this behavior.

        
        
    

    So by adding android:saveEnabled="false" on your EditText will fix the problem and the setText will not be called when view comes to foreground.

    This is what I did and problem was solved.

提交回复
热议问题