【发布时间】:2023-04-11 09:33:02
【问题描述】:
我在组活动中有一个片段,我想用另一个片段替换它:
FragmentTransaction ft = getActivity().getFragmentManager().beginTransaction();
SectionDescriptionFragment bdf = new SectionDescriptionFragment();
ft.replace(R.id.book_description_fragment, bdf);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(null);
ft.commit();
当它作为一个单独的项目完成而不使用活动组时它工作正常,每件事在 log cat 中都工作正常,因为控制进入 getview(),但是没有视图是可见的,甚至没有出现任何异常,我想要这本书细节片段被部分细节片段替换。
图书详细信息片段的 xml 具有 id book_description_fragment,章节描述片段的 xml 具有 id section_description_fragment。
上面的代码在一个项目的onClick方法中,我希望当用户在水平滚动视图中点击一个项目时,片段会发生变化。
【问题讨论】:
标签: java android android-fragments