What's the essential difference between these two methods? When I create a TextView, should I use one over the other for performance?
Edit: What's the difference from
onCreateView() {
root = some view
View v = new View(some context);
root.add(v);
return root;
}
onViewCreated() {
View v = new View(some context);
getView().add(v);
}
It's better to do any assignment of subviews to fields in
onViewCreated
. This is because the framework does an automatic null check for you to ensure that your Fragment's view hierarchy has been created and inflated (if using an XML layout file) properly.Code snippet from: FragmentManger.java
onViewCreated
is called immediately afteronCreateView
(the method you initialize and create all your objects, including yourTextView
), so it's not a matter of performance.From the developer site: