如何将 FragmentActivity 添加到 FrameLayout
How to Add FragmentActivity to FrameLayout
场景:
我有 mainActivity
,其中包含默认 game list fragment
当用户单击列表中的项目时,它应该显示 FragmentActivity
,其中包含一个带有两个选项卡的 viewpager framelayout
基本上替换了默认游戏 list fragment
.
问题:如何将FragmentActivity
添加到FrameLayout
?
我试过的:
//this throws an error because the fragment cannot be casted to `FragmentActivity`
Fragment fragment = (NewsTopicsFragment) ft.findFragmentById(R.id.container);
//Fragment mNewsTopicsFragment =(Fragment) new NewsTopicsFragment();
//mNewsTopicsFragment.setGame(mGame);
getActivity()
.getSupportFragmentManager().beginTransaction()
.replace(R.id.container, mNewsTopicsFragment)
.commit();
您应该用片段替换此 fragmentActivity。您可以嵌套片段,这样应该不会有太大变化,然后您就可以将片段添加到 frameLayout。
场景:
我有 mainActivity
,其中包含默认 game list fragment
当用户单击列表中的项目时,它应该显示 FragmentActivity
,其中包含一个带有两个选项卡的 viewpager framelayout
基本上替换了默认游戏 list fragment
.
问题:如何将FragmentActivity
添加到FrameLayout
?
我试过的:
//this throws an error because the fragment cannot be casted to `FragmentActivity`
Fragment fragment = (NewsTopicsFragment) ft.findFragmentById(R.id.container);
//Fragment mNewsTopicsFragment =(Fragment) new NewsTopicsFragment();
//mNewsTopicsFragment.setGame(mGame);
getActivity()
.getSupportFragmentManager().beginTransaction()
.replace(R.id.container, mNewsTopicsFragment)
.commit();
您应该用片段替换此 fragmentActivity。您可以嵌套片段,这样应该不会有太大变化,然后您就可以将片段添加到 frameLayout。