Android视图关闭某些视图的隐式状态保留 [英] Android view turn off implicit state retaining for some view
问题描述
我有自定义 查看
,它在同一活动中多次动态添加。
I have custom View
which is dynamically added multiple times in same activity.
每个自定义视图实例旁边都有一个 TextView
子元素。
TextView
有 ID ,每个视图实例都相同。
Each of custom view instance has beside other stuff a TextView
child.
The TextView
has it's ID and it is same for each view instance.
对于每个自定义视图实例,我在创建活动时为 TextView
设置了不同的文本
。
当我旋转屏幕时,活动被重新创建,但现在每个 TextView
显示相同的文本
(文本是与最后一个实例的文本相同。)
For each custom view instance I set different Text
for TextView
when activity is created.
When I rotate the screen, the activity is recreated but now each TextView
displays same Text
(text is same as text of the last instance).
这是因为实例状态的保存和恢复会自动保存一些信息,但这些信息显然与ID相关联在我的情况下会产生问题。
有没有办法禁用特定视图的自动状态保留?
Is there a way to disable automatic state retaining for particular views?
是否有属性或设置或某些解决方法?
Is there a property or setting or some workaround?
推荐答案
您可以使用View.setSaveEnabled(已启用布尔值)
方法。
You can use View.setSaveEnabled (boolean enabled)
method.
还可以使用 saveEnabled $ c通过
xml
禁用自动状态保存$ c>属性 android:saveEnabled =false
It's also possible to disable automatic state saving via xml
using saveEnabled
attribute android:saveEnabled="false"
这篇关于Android视图关闭某些视图的隐式状态保留的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!