1

我使用FragmentPageAdapter在我的應用程序中有多個選項卡。其中1個選項卡是ListFragment,應該使用FragmentTransaction替換爲另一個片段onItemClick在FragmentPagerAdapter的1個選項卡中提交FragmentTransaction

的變化更換工程完美,如果我添加了ListFragmentFrameLayoutActivity裏面,但我不知道如何使用FragmentPagerAdapter做到這一點。

這裏有一個更好的解釋:

Tab1  Tab2  Tab3  Tab4 
fragment fragment fragment fragment 
subclass subclass subclass listview 

從片段列表視圖中單擊一個項目後,就應及時更換這樣

Tab1  Tab2  Tab3  Tab4 
fragment fragment fragment fragment 
subclass subclass subclass another-one 

我使用.replace(((ViewGroup)getView().getParent()).getId(), newFragment).commit()試過,但它不工作。

+0

你還在嗎? –

+0

是的,還沒有解決這個問題 –

回答

-1

我只會放棄這個想法並更改爲使用Activity

1

如果你知道它總是要取代Fragment,那麼爲什麼不使用小孩Fragment

代替使用getFragmentManager(),您可以使用getChildFragmentManager()並將FrameLayout置於您用於Fragment的佈局的頂部。

+0

這不是我所需要的。我沒有使用FrameLayout,但是片段由FragmentPagerAdapter管理。 –

+0

這沒什麼區別。在'Fragment'佈局中放置一個'FrameLayout'作爲視圖。 –

+0

你的意思是第4個選項卡包含一個帶有FrameLayout的片段,並且在該FrameLayout中,我放置了我想要切換的2個片段? –

相關問題