onCreate是指创建该fragment,类似于Activity.onCreate,你可以在其中初始化除了view之外的东西;
onCreateView是创建该fragment对应的视图,你必须在这里创建自己的视图并返回给调用者。
例如
-
@Override
-
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
-
View rootView = inflater.inflate(R.layout.main,container,false);
-
mLine1 = (TextView)rootView.findViewById(R.id.line1);
-
mLine2 = (TextView)rootView.findViewById(R.id.line2);
-
mDescription1 = (TextView)rootView.findViewById(R.id.line1_description);
-
mDescription2 = (TextView)rootView.findViewById(R.id.line2_description);
-
mVersion = (TextView)rootView.findViewById(R.id.version);
-
mSignWifi = (TextView)rootView.findViewById(R.id.advice);
-
mSignStreaming = (LinearLayout)rootView.findViewById(R.id.streaming);
-
mSignInformation = (LinearLayout)rootView.findViewById(R.id.information);
-
mPulseAnimation = AnimationUtils.loadAnimation(mApplication.getApplicationContext(), R.anim.pulse);
-
mTextBitrate = (TextView)rootView.findViewById(R.id.bitrate);
-
return rootView ;
-
}
-
部分代码在onCreateView中调用super.onCreateView。
其实有没有调用都无所谓,因为super.onCreateView是直接返回null的。
PS:
基本上,本座可以这么认为这两个东西类似于c#中的构造函数及Form_Load(),也许不严谨,但不重要!!
来自博客:
http://blog.csdn.net/loovejava/article/details/37765993
阅读(2912) | 评论(0) | 转发(0) |