Reputation: 8112
Is it safe to assume that an Activity
's root view will always be a ViewGroup
? I have an Activity
that displays various Fragment
s. Can I skip creating a layout XML for the Activity
and directly add Fragment
s to its root view?
Upvotes: 2
Views: 2798
Reputation: 39836
yes it does work. The Activity root will always be a ViewGroup (otherwise how would you or the framework be able to put other views inside it when inflating the XML?)
Furthermore (to make the answer complete), it's a well known/well documented ID
getSupportFragmentManager()
.beginTransaction()
.replace(android.R.id.content, fragment)
.commit();
ps.: the above code was written without looking up, so there might be some typo, somewhere.
Upvotes: 7