Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
显示可以';不能在Android上回收_Android_Android Fragments - Fatal编程技术网

显示可以';不能在Android上回收

显示可以';不能在Android上回收,android,android-fragments,Android,Android Fragments,我正在开发一个应用程序,其中主屏幕完全由Web服务器的响应构建。我们曾经在回收者视图中显示此内容,但由于视图非常复杂,几乎没有共同点,因此滚动不顺畅,因为回收行为非常昂贵 我决定为我必须公开的每种类型的视图创建一个片段,并将它们添加到ScrollView中的LinearLayout中。结果是惊人的。由于片段具有生命周期,并且其数据可以序列化,因此无需回收,卷轴非常平滑,方向更改也变得更好。然而,我遇到了一个新问题: 根据我对这个问题的理解: 为了解决这个问题,我必须包括支持库的来源,我不希望

我正在开发一个应用程序,其中主屏幕完全由Web服务器的响应构建。我们曾经在回收者视图中显示此内容,但由于视图非常复杂,几乎没有共同点,因此滚动不顺畅,因为回收行为非常昂贵

我决定为我必须公开的每种类型的视图创建一个片段,并将它们添加到ScrollView中的LinearLayout中。结果是惊人的。由于片段具有生命周期,并且其数据可以序列化,因此无需回收,卷轴非常平滑,方向更改也变得更好。然而,我遇到了一个新问题:

根据我对这个问题的理解:

为了解决这个问题,我必须包括支持库的来源,我不希望这样,除非这是绝对必要的

有人知道如何以其他方式显示这种动态内容吗

编辑: 这是我现在拥有的代码:

        FragmentTransaction tx = mFragmentManager.beginTransaction();
        mContainerList = new ArrayList<>(containers);

        if(mFragmentManager.getFragments() != null) {
            for (Fragment f : mFragmentManager.getFragments())
                if (f != null)
                    tx.remove(f);
            Collections.reverse(mContainerList);
        }

        for(final InitResult.Container c : mContainerList) {
            InitFragment fragment = null;
            switch (c.getType()) {
                case InitResult.Container.HORIZONTAL_LIST:
                    if (c.getItems() != null && c.getItems().size() > 0 && c.getItems().get(0).getType().equals(InitResult.Container.BANNER))
                        fragment = new InitBannerFragment();
                    else
                        fragment = new InitHListFragment();
                    break;
                case InitResult.Container.GRID:
                    fragment = new InitGridFragment();
                    break;
                case InitResult.Container.BANNER:
                    fragment = new InitBannerFragment();
                    break;
                case InitResult.Container.PROMOTIONAL:
                    fragment = new InitPromotionalFragment();
                    break;
                case InitResult.Container.PROTEGE:
                    fragment = new InitProtegeFragment();
                    break;
                case InitResult.Container.PROTEGE_ACTIVE:
                    fragment = new InitProtegeActiveFragment();
                    break;
            }

            if (fragment != null) {
                fragment.setInitContainer(c);
                tx.add(containerList.getId(), fragment);
            }
        }

        tx.commitAllowingStateLoss();
        mFragmentManager.executePendingTransactions();
FragmentTransaction tx=MFFragmentManager.beginTransaction();
mContainerList=新的ArrayList(容器);
if(MFFragmentManager.getFragments()!=null){
对于(片段f:MFFragmentManager.getFragments())
如果(f!=null)
tx.f;
收藏。反面(McContainerList);
}
for(final InitResult.Container c:mContainerList){
InitFragment fragment=null;
开关(c.getType()){
case InitResult.Container.HORIZONTAL_列表:
如果(c.getItems()!=null&&c.getItems().size()>0&&c.getItems().get(0.getType().equals)(InitResult.Container.BANNER))
fragment=新的InitBannerFragment();
其他的
fragment=新的InitHListFragment();
打破
案例InitResult.Container.GRID:
fragment=新的InitGridFragment();
打破
案例InitResult.Container.BANNER:
fragment=新的InitBannerFragment();
打破
案例InitResult.Container.PROMOTIONAL:
fragment=新的InitPromotionalFragment();
打破
案例InitResult.Container.PROTEGE:
fragment=新的InitProtegeFragment();
打破
案例InitResult.Container.PROTEGE_激活:
fragment=新的InitProtegeActiveFragment();
打破
}
if(片段!=null){
fragment.setInitContainer(c);
tx.add(containerList.getId(),片段);
}
}
tx.佣金和状态损失();
MFFragmentManager.executePendingTransactions();
每当刷新屏幕时,我都运行此代码。请注意,如果我不是第一次这样做,我需要反转容器列表,以便按所需顺序列出它


我的问题发生在新项目来自服务器时,而不仅仅是包含更新内容的列表。如果这个新项目出现,它将不会按所需的顺序排列,而是放在列表的末尾。

您的问题不是很清楚。仅仅链接到bug报告并不一定能解释它是如何影响您的特定场景和代码的。最好描述在您自己的代码中发生的确切问题(并显示您的代码)。然后其他人可以更容易地根据您的具体情况定制解决方案。谢谢您的评论。对不起,我不是很清楚。我为这个问题添加了我目前的解决方案。İ我想你需要重新填充你的McContainerList,并进行一个新的片段事务,以再次填充屏幕。每次更改McContainerList时,我发布的代码都会运行,所以我已经这样做了:)你的问题不是很清楚。仅仅链接到bug报告并不一定能解释它是如何影响您的特定场景和代码的。最好描述在您自己的代码中发生的确切问题(并显示您的代码)。然后其他人可以更容易地根据您的具体情况定制解决方案。谢谢您的评论。对不起,我不是很清楚。我为这个问题添加了我当前的解决方案。İ我想你需要重新填充你的McContainerList,并进行一个新的片段事务,以再次填充屏幕。每次更改McContainerList时,我发布的代码都会运行,所以我已经这样做了:)