Reputation: 805
I am relatively new at Android. I am taking a program on college and I am on my third semester. When we first started looking at fragments in the course, we always created them by right clicking the java folder and directly making a blank fragment. this would create the java file and the xml layout. then we would with help of the fragment manager, replace the content of the activity with the new fragment.
I thought this was the only way of doing it so far, but this week I've started to take a look at the developers course android offers on their website, and looking at the Creating a Fragment section, I learned that you can also just create a class and make it extend Fragment. Then, add an actual xml fragment tag to your layout and link your fragment to this xml.
My concerns about this are:
1) Is both ways doing the same process? 2) Is one of them better than the other? 3) Is there a moment when I'll prefer doing one or the other?
Upvotes: 1
Views: 216
Reputation: 3688
There is no difference. Directly using the "Create a fragment" option is just a convenience option that does the following:
contentView
of your fragment (in the onCreate method)You could do all these steps manually as well.
Upvotes: 3