0

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

t_godd
  • 194
  • 2
  • 3
  • 18

2 Answers2

1

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.

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.

David Conrad
  • 15,432
  • 2
  • 42
  • 54
  • if i make the ArrayList Static and and initialise in the MainActivity, will that help. I wonder, then in OnCrete it won't get overwritten. – t_godd Apr 18 '14 at 19:15
0

dude I am just continuing form the que. If you have done same as you posted code here, just paste this line in onCreateView of Monday_fragment.

 myStringList= MainActivity.getMyStringList();
Community
  • 1
  • 1
maddy d
  • 1,530
  • 2
  • 12
  • 23