admin管理员组文章数量:1122846
I have a layout with some EditText
, like name, surname, city... I include
this layout in another layout a couple of times, so there is two EditText
for the name, surname, etc. The problem I face is if I fill in these fields, for example, in the first EditText
for the name I add "Tom", and in the second "John", and then I rotate the device, both EditText
have "Tom".
Basically, I am facing the same problem than this user: All EditTexts are populated with data from one EditText after rotation and backpressed
As he said, I could manually add the EditText
to the main layour instead of using include
but that would make the XML very messy.
I could also try the user solution, but I don't like it much either, and keeping in mind that the question is 10 years old, I am wondering if there is a better solution.
Thank you.
I have a layout with some EditText
, like name, surname, city... I include
this layout in another layout a couple of times, so there is two EditText
for the name, surname, etc. The problem I face is if I fill in these fields, for example, in the first EditText
for the name I add "Tom", and in the second "John", and then I rotate the device, both EditText
have "Tom".
Basically, I am facing the same problem than this user: All EditTexts are populated with data from one EditText after rotation and backpressed
As he said, I could manually add the EditText
to the main layour instead of using include
but that would make the XML very messy.
I could also try the user solution, but I don't like it much either, and keeping in mind that the question is 10 years old, I am wondering if there is a better solution.
Thank you.
Share Improve this question asked Nov 21, 2024 at 16:39 xerezxerez 797 bronze badges 1- This post answered your question. Please take a look and apply solution to your problem: stackoverflow.com/questions/3542333/… – Son Truong Commented Nov 29, 2024 at 17:21
1 Answer
Reset to default 0The issue may arise in cases where what you are including contains a ViewGroup
, in other words, when there is a parent ViewGroup
of the EditText
where the specific EditText
is. If the "EditText" you are including is actually a layout type that is in a ViewGroup, for example, like a TextInputLayout.
Solution 1
If I remember correctly, you can override these methods so they don't try to restore the states.
override fun dispatchSaveInstanceState(container: SparseArray<Parcelable>) {
// Nothing
}
override fun dispatchRestoreInstanceState(container: SparseArray<Parcelable>) {
// Nothing
}
Solution 2
Set attribute android:saveEnabled
to false and use onSaveInstanceState()
or a ViewModel
本文标签: androidEditTexts are populated with same data after rotationStack Overflow
版权声明:本文标题:android - EditTexts are populated with same data after rotation - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736308815a1933796.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论