问题
I have a follow up question from my previous questions.
My app starts and fragment loads, it passes in the arraylist correctly using interface and listener method .. Now when I click on navigation button to replace current fragment with another fragment... That fragment is exactly the same as first fragment but with different array list... How would I update the arraylist in activity?
I get a classcast exception.
Here are how both of my fragments are implemented
Pass Arraylist from fragment to its own Activity
回答1:
In terms of the ClassCastException, did you make sure to have your MainActivity(know its MainActivity from MainActivity.java:107) implement the OnFragmentInteractionListener? If you don't that could be why you're getting that ClassCastException, because you're trying to cast your an activity instance(getActivity) to a subclass of which it does not share any inheritance relationship with (OnFragmentInteractionListener)
来源:https://stackoverflow.com/questions/26966752/passing-arraylist-from-multiple-fragments-to-activity