一种观点的"标签"恢复时,其布局的活动包含的观点是重现? [英] is a view's "tag" restored when the activity whose layout contains the view is recreated?

查看:125
本文介绍了一种观点的"标签"恢复时,其布局的活动包含的观点是重现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助文档关于活动休闲状态:

  

默认情况下,系统采用了包实例的状态保存   关于你的活动布局中的每个查看对象的信息(如   )签订了一个EditText对象的文本值。所以,如果你的活动   实例被破坏,重建,布局的状态   恢复到previous状态与您不需要code。

的<一个href="http://developer.android.com/reference/android/view/View.html#setTag%28java.lang.Object%29">docs对于View.setTag(对象)状态:

  

设定与该视图关联的标签。一个标记可以被用于标记   查看其层次结构,并且不必须是内唯一   层次。标签也可以用来存储一个视图内的数据,而不   借助于另一数据结构

我的问题是:如果我在一个视图设置一个标记(即具有唯一的ID),在我活动的布局,然后该活动是由系统破坏,随后重新创建,将这种意见,重建的时候,会自动将标记为我最初设置的对象?

解决方案
  

如果我在一个视图设置一个标记(即具有唯一的ID),在我活动的布局,然后该活动是由系统破坏,随后重新创建,将这种意见,重建时,自动标记对象我最初设置?

没有,根据我的阅读源$ C ​​$ C。

  

该系统预计将重新在以后的日子该活动,所以我可以看到它保持周围的引用,原始标签。

这并不总是可能的,因为保存的实例状态捆绑必须是跨越进程边界运输。

The docs concerning Activity recreation state:

By default, the system uses the Bundle instance state to save information about each View object in your activity layout (such as the text value entered into an EditText object). So, if your activity instance is destroyed and recreated, the state of the layout is restored to its previous state with no code required by you.

The docs for View.setTag(Object) state:

Sets the tag associated with this view. A tag can be used to mark a view in its hierarchy and does not have to be unique within the hierarchy. Tags can also be used to store data within a view without resorting to another data structure.

My question is: if I set a tag on a View (that has a unique id) in my activity's layout and then the activity is destroyed by the system and subsequently re-created, will that view, when recreated, automatically be tagged with the Object I originally set?

解决方案

if I set a tag on a View (that has a unique id) in my activity's layout and then the activity is destroyed by the system and subsequently re-created, will that view, when recreated, automatically be tagged with the Object I originally set?

No, based on my reading of the source code.

The system expects to recreate the activity at some later date, so I could see it keeping around a reference to the original tag.

That is not always possible, as the saved instance state Bundle needs to be transportable across process boundaries.

这篇关于一种观点的&QUOT;标签&QUOT;恢复时,其布局的活动包含的观点是重现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆