I have tried using Static variable for the ArrayList but in the ListFragment class, while debugging it\'s value is null.
I think the ListFragment gets created before
I have seen your code for your given link and thats why I am posting a new Ans. One thing if you read your code carefully, you have declared ArrayAdapter
in Monday_fragment
, so this list initialize every time when you replace this fragment with other. So just create a ArrayAdapter
in MainActivity
and getter, setter
for the same and change your methode ArrayList
in the Monday_fragment
like below
public ArrayList toStringList(Collection entryLogs) {
ArrayList stringList = ((MainActivity)getActivity()).getMyStringList();
for (DiaryLogs myobj : entryLogs) {
String objctString = myobj.toString();
stringList.add(objctString);
}
((MainActivity)getActivity()).setMyStringList(stringList);
return stringList;
}