我明白了!
让我解释一下,您需要在您要替换的Layout上放置一个ID,例如:
<frameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/framelay" android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/txtSearchTopic" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" android:text="TextView" /></frameLayout>
所以我就放我的:android:id =“ @ + id /
framelay”然后,我可以使用此ID替换新的片段,我的意思是,此Layout中的所有内容都将被新的Fragment替换,例如我叫DetailFragment。
FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); DetailFragment fragment3 = new DetailFragment(); fragmentTransaction.replace(R.id.framelay, fragment3); fragmentTransaction.commit();



