How to set a Fragment tag by code?

Axel M. Garcia picture Axel M. Garcia · Jun 16, 2011 · Viewed 176.1k times · Source

I haven't found something like setTag(String tagName) method in the Fragment class. The only way to set a Fragment tag that I have found is by doing a FragmentTransaction and passing a tag name as parameter.

Is this the only way to explicitly set a Fragment tag by code?

Answer

PJL picture PJL · Jun 17, 2011

Yes. So the only way is at transaction time, e.g. using add, replace, or as part of the layout.

I determined this through an examination of the compatibility sources as I briefly looked for similar at some point in the past.