Fragment中的onCreate()和onCreateView()生命周期方法有什么不同? [英] what is the different between onCreate() and onCreateView() lifecycle methods in Fragment?

查看:1106
本文介绍了Fragment中的onCreate()和onCreateView()生命周期方法有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道何时使用 onCreate() onCreateView()



我已经使用了 onCreate() onCreateView()生命周期方法。
我认为 onCreate()用于Activity, onCreateView()用于Fragment。但我不确定。我可以在Fragment中使用 onCreate() LifeCycle方法吗?我希望有人能帮助我! 在创建片段时调用onCreate 。 你在这里做你的非图形化初始化。它甚至可以在布局膨胀之前完成,并且碎片可见。



onCreateView 被调用来扩大碎片的布局,通常是图形化初始化发生在这里。它总是在 onCreate 方法之后调用。


I don't know when to use onCreate() or onCreateView().

I have used onCreate() and onCreateView() lifecycle methods. I think onCreate() for Activity and onCreateView() for Fragment. But I am not sure. Can I use onCreate() LifeCycle method in Fragment? I hope somebody can help me!

解决方案

onCreate is called on initial creation of the fragment. You do your non graphical initializations here. It finishes even before the layout is inflated and the fragment is visible.

onCreateView is called to inflate the layout of the fragment i.e graphical initialization usually takes place here. It is always called sometimes after the onCreate method.

这篇关于Fragment中的onCreate()和onCreateView()生命周期方法有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆