android - 如何防止破坏碎片
问题描述
在我的活动中,我通过以下代码加载 4 个片段:
supportFragmentManager.beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.replace(R.id.frame, fragmentList[0])
.commit()
但问题是每个片段都有大量数据,应该从服务器加载大量数据。这需要一点点。我希望我的片段在我更改它们以防止再次加载数据时不会被破坏。我怎样才能做到这一点?有什么办法可以隐藏碎片而不是破坏,通过加载,它们就会出现?
解决方案
而不是替换使用.add(containerId, newFragment)
然后.hide(currentFragment)
编辑:
supportFragmentManager.beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.add(R.id.frame, fragmentList[0])
.hide(fragmentList[1]) // assumed that fragmentList[1] is your current fragment
.commit()
推荐阅读
- javascript - 用 JavaScript 做一个问答游戏,我如何创建一个数据库来保存用户的分数?
- javascript - MultiValueDictKeyError 在 Django 中访问相同的表单元素
- php - 使用 RewriteRule 后未打开 index.php
- c# - 无法在 V/Studio 2019 中“跨步”进入代码
- java - Thymeleaf - 不会显示 6 个 getter 方法中的 1 个
- ffmpeg - FFMPEG 中的 `-map data-re` 选项有什么作用?
- html - 如何使用响应式定位将最后一个列表项与底部对齐
- c - C中的Bspline基函数
- c# - C# WindowsForm 将 DatagridView 内容添加到 PowerPoint 的幻灯片中
- flutter - Fluter 跨平台网页版和移动版