0
對我有btnToggle
和fragment_text
。 在Android Studio中,如何使用java代碼將片段切換到另一個片段
我希望當用戶點擊btnToggle
切換fragment_text
到fragment_image
。
private void btnToggle_OnClick() {
//what goes here?
}
對我有btnToggle
和fragment_text
。 在Android Studio中,如何使用java代碼將片段切換到另一個片段
我希望當用戶點擊btnToggle
切換fragment_text
到fragment_image
。
private void btnToggle_OnClick() {
//what goes here?
}
首先動態地添加片段,然後替換象下面這樣: -
FragmentTransaction ft = getActivity().getFragmentManager().beginTransaction();
SectionDescriptionFragment bdf = new SectionDescriptionFragment();
ft.replace(R.id.book_description_fragment, bdf);
ft.commit();
動態地添加片段可以按照http://wptrafficanalyzer.in/blog/dynamically-add-fragments-to- an-activity-in-android/ – Ramit
什麼是'SectionDescriptionFragment'? – MakPo
僅限其示例。你可以使用你自己的片段名稱,類似於鏈接中提到的例子。 – Ramit