简体   繁体   English

如何使用隐藏/显示标记片段?

[英]How to tag fragments using hide/show?

in my app i have been using add/replace to transact my fragments. 在我的应用程序中,我一直在使用添加/替换来处理我的片段。 To find the unique references lateron for checking which view is active, i tagged them like this: 为了稍后找到唯一的引用以检查哪个视图处于活动状态,我像这样标记了它们:

fm.beginTransaction()
  .replace(R.id.customer_details_fragment, fragment, "MyUniqueTag")
  .commit(); 

now i read some more details on how the fragments work and i figured that i should use hide/show for the fragment-transaction because its saving alot of cpu-load if you just have to re-draw the views. 现在,我阅读了有关片段如何工作的更多详细信息,并且我认为应该对片段事务使用隐藏/显示,因为如果您只需要重新绘制视图,它可以节省大量的CPU负载。

My question is : Does it make sense to use tags in context with hide/show aswell and if so, how do i tag them? 我的问题是 :在具有隐藏/显示功能的上下文中使用标签是否有意义,如果可以,如何标记标签?

FragmentTransaction ft = getFragmentManager().beginTransaction();
                ft.show(fragment);
                ft.hide(fragment);
                ft.commit();

"Shows a previously hidden fragment. This is only relevant for fragments whose views have been added to a container." “显示以前隐藏的片段。这仅与将视图添加到容器的片段有关。” - To use this function you must also add the fragment to a container. -要使用此功能,您还必须将片段添加到容器中。 So you can set a tag at this point as usual. 因此,您可以像往常一样在此时设置标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM