为什么将片段从第一个(pageNews)更改为第二个(pageViewFromWeb)“findFragmentById”返回对第一个(pageNews)片段的引用?
布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:paddingTop="10dp"
android:background="#000">
<FrameLayout
android:id="@+id/frgmCont"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">
</FrameLayout>
</RelativeLayout>
代码:
fTrans = getSupportFragmentManager().beginTransaction();
fTrans.add(R.id.frgmCont, pageNews);
....
....
public void selectNews(String news_id) {
// Toast.makeText(this, news_id, Toast.LENGTH_SHORT).show();
fTrans = getSupportFragmentManager().beginTransaction();
fTrans.replace(R.id.frgmCont, pageViewFromWeb);
fTrans.commit();
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.frgmCont);
...
}