保存片段状态操作栏选项卡

编程入门 行业动态 更新时间:2024-10-28 18:28:13
本文介绍了保存片段状态操作栏选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在构建一个由带选项卡的操作栏组成的应用程序,每个选项卡均由一个片段组成.片段之一具有需要加载的数据.因此,我希望仅在第一次加载数据.当用户更改选项卡并返回到包含该片段的选项卡时,无需等待数据再次加载.我假设我必须使用某种保存数据的方式,以便下次用户返回该特定片段时可以使用该数据.但是我只是不知道应该使用哪种方法.如果有人知道或可以提出保存片段状态的示例,请告诉我.谢谢你!

I am building an app that consists of actionbar with tabs, and each tab consists of a fragment. One of the fragments has data that need to be loaded. So I want the data to be loaded only the first time. When the user changes the tabs and goes back to the one containing that fragment, doesn't wait for the data to be loaded again. I assume I have to use some kind of saving the data so that it can be used the next time the user goes back to that particular fragment. But I just do not know what method I should use. If someone knows or can suggest an example of saving fragment state, please let me know. Thank u!

推荐答案

尝试一下:

myFragment.setRetainInstance(true);

这意味着不会在每次添加片段时都重新创建该片段.

It'll mean the fragment isn't recreated every time it's added.

更多推荐

保存片段状态操作栏选项卡

本文发布于:2023-10-12 21:49:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485994.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:选项卡   片段   状态   操作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!