Why EditText in a custom compound view is re-using the text entered in another compound view instance?

前端 未结 6 683
一个人的身影
一个人的身影 2020-12-24 08:21

I\'m trying to write a custom compound view composed by a TextView and an EditText, _compound_view.xml_:



        
6条回答
  •  青春惊慌失措
    2020-12-24 08:50

    I'll start off by saying that I haven't confirmed this... but I experienced the same issues when using a compound view, similar to what you were doing.

    I think the root of the problem is how Android automatically saves the state of EditText controls, and I think it saves it by "id". So if you have multiple controls in your xml with same "id", then when it saves state, and then restores state, all controls with the same id get the same value. You can try this by adding 2 EditText contols to you normal xml and give them the same android:id value and see if they end up getting the same value.

    In your case, you can try to NOT use ids in the compound view and rather find the elements another way, either by tag (View.findViewWithTag), or by name, and see if that makes a difference.

    In my case, I solved the problem by doing the latter.

提交回复
热议问题