问题描述
第一的onClick在Monday_fragment它增加了数据的ArrayList。
第二的OnClick在Monday_fragment花费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.
codeS
Monday_fragment
https://github.com/tirthoguha/DroidProject/blob/myDiary/src/com/example/s0217980_diary/Monday_fragment.java
Monday_list_fragment
https://github.com/tirthoguha/DroidProject/blob/myDiary/src/com/example/s0217980_diary/Monday_list_fragment.java
推荐答案
在片段开始时,它会创建一个新的空单。在第一个的onClick
在 Monday_fragment
,它用一个来自 entryLogs 创建的列表code>。当您从
Monday_list_fragment
返回时,的onCreate
方法被调用,并且列表和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
方法可以被调用多次,包括当设备方向的变化。你需要重新思考,当你设置你的片段的状态如何以及
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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!