我在组活动中有一个片段,我想用另一个片段替换它:
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();
Run Code Online (Sandbox Code Playgroud)
它在没有使用活动组的情况下作为单独的项目完成时工作正常,因为控件进入getview()内部,每个东西都可以在log cat中正常工作,但是没有视图可见,甚至没有出现任何异常,我希望书籍详细信息片段为由部分细节片段替换.
书籍详细信息片段的Xml具有id book_description_fragment,而用于部分描述片段的xml具有id section_description_fragment.
上面的代码在项目的onClick方法中,我希望当用户点击水平滚动视图中的项目时,片段会发生变化.