Passing arraylist from multiple fragments to activity

為{幸葍}努か 提交于 2019-12-25 04:22:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!