简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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