Commiting FragmentTransaction in 1 Tab of a FragmentPagerAdapter

折月煮酒 提交于 2019-12-13 02:26:16

问题


I'm using FragmentPageAdapter to have multiple tabs within my app. 1 of those tabs is a ListFragment that is supposed to be replaced by another fragment onItemClick, using FragmentTransaction.

The change replace works perfectly if I add the ListFragment to a FrameLayout inside an Activity, but I'm not sure how to do this using FragmentPagerAdapter.

Here's a better explanation:

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

after clicking on one item from the fragment listview it should be replaced like this

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

I tried using .replace(((ViewGroup)getView().getParent()).getId(), newFragment).commit(), but it doesn't work.


回答1:


If you know it's always going to replace the Fragment on that page, then why not use a child Fragment?

Instead of using getFragmentManager() you use getChildFragmentManager() and put the FrameLayout at the top of the layout that you're using for the Fragment.




回答2:


I'll just drop this idea and change to use Activity.



来源:https://stackoverflow.com/questions/18968972/commiting-fragmenttransaction-in-1-tab-of-a-fragmentpageradapter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!