Fragment的onCreate和onCreateView区别

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的。

你可能感兴趣的:(Android)