ViewPager碎片问题的内部碎片、问题、ViewPager

2023-09-04 11:09:26 作者:从头再来

我有问题,认为寻呼机这是一些片段里。要与我使用FragmentPagerAdapter观点寻呼机工作。试图运行我的应用程序时,递归进入executePendingTransactions 的例外:和肯定,我得到的 java.lang.IllegalStateException。

I'm having problem with view pager which is inside of some fragment. To work with view pager I'm using FragmentPagerAdapter. And sure I'm getting java.lang.IllegalStateException: Recursive entry to executePendingTransactions exception when trying to run my app.

很多人说这是不可能有FragmentPagerAdapter其他片段里面,所以我很抱歉,如果这个问题是无效的。我只是希望,也许有人有这个问题及其可能的解决方案的一些新的想法。

Most people say it's impossible to have FragmentPagerAdapter inside other fragment, so I'm sorry if this question is invalid. I was just hoping that maybe someone has some fresh ideas about this problem and its possible solution.

P.S。我有一个建议的AsyncTask内设置适配器(我可以澄清这种情况下,如果有人需要的话),但这种方法与恢复等片段状态相关的一些缺陷,所以它的工作对我来说。的

推荐答案

开始采用Android 4.2,您可以使用嵌套的片段的。 Android的支持库now还包括对这个的支持,所以你可以使用它与旧的Andr​​oid版本。

Starting with Android 4.2, you can use nested fragments. The Android support library now also includes support for this, so you can use it with older Android versions.

时的基本模式是这样的:

The basic pattern looks like this:

Fragment videoFragment = new VideoPlayerFragment();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.add(R.id.video_fragment, videoFragment).commit();