What is the difference between onCreate() and onCreateView() lifecycle methods in Fragment ?
What is the difference between onCreate() and onCreateView() lifecycle methods in Fragment ?
The main difference between onCreate()
and onCreateView()
lifecycle methods in an Android Fragment is:
onCreate()
is called to do initial fragment setup, such as creating views and non-UI related components. It is called after the fragment has been associated with its activity. Here you can initialize variables, create views, etc. but you cannot access the parent view hierarchy yet[1][3].
onCreateView()
is called to have the fragment instantiate its user interface view. It is called after onCreate()
and provides a View
object that is the root of the fragment's layout. This is where you inflate the fragment's layout file. The inflated layout is returned as the View
for the fragment[1][3][4].
In summary:
onCreate()
is for initializing the fragment itself, while onCreateView()
is for inflating the fragmen...middle
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào