简体   繁体   English

将数组列表从多个片段传递到活动

[英]Passing arraylist from multiple fragments to activity

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? 我的应用程序启动并加载片段,它使用接口和侦听器方法正确地传递到arraylist中。.现在,当我单击导航按钮以将当前片段替换为另一个片段时...该片段与第一个片段完全相同,但具有不同的数组list ...如何更新活动中的arraylist?

I get a classcast exception. 我收到一个classcast异常。

Here are how both of my fragments are implemented 这是我两个片段的实现方式

Pass Arraylist from fragment to its own Activity 将Arraylist从片段传递到其自己的Activity

In terms of the ClassCastException, did you make sure to have your MainActivity(know its MainActivity from MainActivity.java:107) implement the OnFragmentInteractionListener? 就ClassCastException而言,您是否确定要使MainActivity(从MainActivity.java:107知道其MainActivity)实现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) 如果不是这样,那可能就是为什么您得到那个ClassCastException的原因,因为您试图将一个活动实例(getActivity)强制转换为一个与(OnFragmentInteractionListener)不共享任何继承关系的子类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM