The Difference between onCreateView and onViewCreated in Fragment

来源:互联网 发布:windows linux 编辑:程序博客网 时间:2024/05/18 02:36

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);}


Fragment的生命周期,我相信了解过的开发人员都应该把以下方法脱口而出:onAttach, onCreate, onCreateView, onViewCreated, onActivityCreated, onStart, onResume, onPause, onStop, onDestroyView, onDestroy, onDetach.

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);}



 

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);}


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);}

onViewCreated is called immediately after onCreateView (the method you initialize and create all your objects, including your TextView), so it's not a matter of performance.


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);}

onViewCreated(View view, Bundle savedInstanceState)

Called immediately after onCreateView(LayoutInflater, ViewGroup, Bundle) has returned, but before any saved state has been restored in to the view. This gives subclasses a chance to initialize themselves once they know their view hierarchy has been completely created. The fragment's view hierarchy is not however attached to its parent at this point.



11down votefavorite
1

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);}
0 1