Pass ArrayList from fragment to another fragment(extends ListFragment) using bundle, seListAdapter runtime error

后端 未结 2 1331
生来不讨喜
生来不讨喜 2021-01-15 11:50

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

2条回答
  •  借酒劲吻你
    2021-01-15 12:13

    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 toStringList(Collection entryLogs) 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;
    }
    

提交回复
热议问题