导航回到FragmentPagerAdapter - >片段是空的 [英] Navigating back to FragmentPagerAdapter -> fragments are empty

查看:100
本文介绍了导航回到FragmentPagerAdapter - >片段是空的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是很难把整个场景的称号,那就是:

It was hard to put the whole scenario in the title, here it is:

我有一个片段(我称之为pagerFragment)被添加到backstack,是可见的。它拥有一个FragmentPagerAdapter一个viewPager。该FragmentPagerAdapter持有(比方说)两个片段:A和B

I have a Fragment (I'll call it pagerFragment) that is added to the backstack and is visible. It holds a viewPager with a FragmentPagerAdapter. The FragmentPagerAdapter holds (let's say) two fragments: A and B.

首先加入片段的伟大工程。

First adding of the fragments works great.

片段A有一个按钮,一旦点击,增加了一个片段(C)的backstack。

Fragment A has a button that once clicked, adds a fragment (C) to the backstack.

问题是这样的:如果我再补充一点片段(C),然后单击回来,pagerAdapter是空的,我看不到里面的任何片段

The problem is this: if I add that fragment (C), and then click back, the pagerAdapter is empty, and I cannot see any fragments inside.

如果我用一个黑客攻击,并摧毁了孩子的片段(A和B)在pagerFragments onDestroyView(),这个问题解决了,虽然我不wan't使用这个技巧。

If I use a hack, and destroy the children fragments (A and B) in the pagerFragments onDestroyView(), this solves the problem, although I don't wan't to use this hack.

任何想法的问题可能是什么?

Any ideas what the issue could be?

感谢

推荐答案

我有同样的问题。对我来说,解决办法很简单:

I had the same problem. The solution for me was simple:

在onCreateView我有:

in onCreateView I had:

// Create the adapter that will return a fragment for each of the three
// primary sections of the app.
mSectionsPagerAdapter = new SectionsPagerAdapter(getActivity()
    .getSupportFragmentManager());

在这里SectionPageAdapter是这样的:

where SectionPageAdapter is something like this:

class SectionsPagerAdapter extends FragmentPagerAdapter {
...
}

改变getSupportFragmentManager后

after changing getSupportFragmentManager to

mSectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());

它开始工作! 希望这有助于。

it started working! Hope this helps.

这篇关于导航回到FragmentPagerAdapter - >片段是空的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆