回到片段 ArrayList 变空时(恢复 ArrayList) [英] on coming back to fragment ArrayList getting empty (restore ArrayList)

查看:43
本文介绍了回到片段 ArrayList 变空时(恢复 ArrayList)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Monday_fragment 中的第一次 onClick 将数据添加到 ArrayList.Monday_fragment 中的第二个 OnClick 需要在 Monday_list_fragment 显示列表.Monday_list_fragment 中有一个按钮可以将其带回 Monday_fragment.我调试了一个看到,当我回来时,ArrayList 中的所有数据都不见了.如何保持 ArrayList 数据在返回时不被清除.

first onClick in Monday_fragment it adds the data to ArrayList. Second OnClick in Monday_fragment it takes to Monday_list_fragment where the list is shown. There is a button in Monday_list_fragment which brings it back to the Monday_fragment. I debugged an seen, when i came back all the data in ArrayList is gone. How to keep the ArrayList data not to clear out on coming back.

代码

Monday_fragmenthttps://github.com/tirthoguha/DroidProject/blob/myDiary/src/com/example/s0217980_diary/Monday_fragment.java

Monday_list_fragmenthttps://github.com/tirthoguha/DroidProject/blob/myDiary/src/com/example/s0217980_diary/Monday_list_fragment.java

推荐答案

片段启动时,会创建一个新的空列表.在 Monday_fragment 中的第一个 onClick 中,它将列表替换为从 entryLogs 创建的列表.当您从 Monday_list_fragment 返回时,将调用 onCreate 方法,并且 list 和 entryLogs 被新的空的覆盖.

When the fragment is started, it creates a new, empty list. In the first onClick in Monday_fragment, it replaces the list with one created from entryLogs. When you return from Monday_list_fragment, the onCreate method is called, and the list and entryLogs are overwritten with new, empty ones.

onCreate 方法可以被多次调用,包括当设备方向改变时.您需要重新考虑如何以及何时设置 Fragment 的状态.

The onCreate method can be called multiple times, including when the device orientation changes. You need to rethink how and when you set up the state of your fragment.

这篇关于回到片段 ArrayList 变空时(恢复 ArrayList)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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