首页 > 代码库 > Android Fragment

Android Fragment

1. add a fragment to a view

FragmentManager fm = getFragmentManager();FragmentTransaction ft = fm.beginTransaction();ft.add(R.id.fragment_container, mFriendsFragment);ft.addToBackStack(null);// this is optional, use this if you want to come back to the old fragmentft.commit();

main activity view

<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/fragment_container"    android:layout_width="match_parent"    android:layout_height="match_parent" />

 

Android Fragment