Activity
FragmentDemo fram = new FragmentDemo();
FragmentManager manager = getFragmentManager();
FragmentTransaction transfo = manager.beginTransaction();
// 点击back键回到刚才的Fragment
transfo.addToBackStack(null);
transfo.replace(R.id.frame, fram);
transfo.commit();
Fragment
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_01, container,false);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
XML
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/fram"
></FrameLayout>