fragment生命周期:
1.onCreate()
2.onStart()
3.onResume()
当调用onStart(),fragment并不可见,当onResume()之后才可见
切换fragment时,依次调用上一个fragment的 onPause(),onStop(), onDestroy(),这与Activity相似,调用onPause()时,fragment只是暂停,onStop()之后fragment变为不可见
在Activity的生命周期里,在Activity中显示一个Dialog时,当前Activity只是调用了onPause(),并不调用onStop()
TabHost也可以实现fragment的功能
1)首先Activity继承TabActivity,创建TabHost控件,在xml文件中写的时候要注意,指定id时,只能指定特定的id,代码如下
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="60dp"
></TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</TabHost>
这是因为加载TabHost不用findViewById,而用getTabHost(),用getTabHost()时,源码里加载时用的id是上述代码指定的id;