从多个片段活动传递的ArrayList [英] Passing arraylist from multiple fragments to activity

查看:202
本文介绍了从多个片段活动传递的ArrayList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从previous问题的后续问题。

I have a follow up question from my previous questions.

我的应用程序启动和加载片段,它通过ArrayList中正确使用接口和监听方法。现在,当我的导航按钮,单击另一个片段,以取代当前片段...这片段是完全一样的第一个片段,但不同的数组列表...我怎么会更新活动ArrayList中?

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?

我得到一个classcast例外。

I get a classcast exception.

下面是如何我的两个片段实施

Here are how both of my fragments are implemented

通行证的ArrayList从片段自身活动

推荐答案

在抛出ClassCastException而言,你要确保有你MainActivity(从知道其MainActivity.java:107 MainActivity)实施OnFragmentInteractionListener?如果不这样做,可能是为什么你得到了ClassCastException异常,因为你想你的活动实例(getActivity)转换为其中不共享(OnFragmentInteractionListener)

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)

这篇关于从多个片段活动传递的ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆