如何通过的ArrayList< CustomeObject>从一个活动到另一个? [英] How to pass ArrayList<CustomeObject> from one activity to another?

查看:189
本文介绍了如何通过的ArrayList< CustomeObject>从一个活动到另一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个活动发送下面的ArrayList到另一个请帮助。

I want to send Following ArrayList from one activity to another please help.

ContactBean m_objUserDetails = new ContactBean();
ArrayList<ContactBean> ContactLis = new ArrayList<ContactBean>(); 

我在里面添加数据如下发送后上面的ArrayList

I am sending the above arraylist after adding data in it as follows

  Intent i = new Intent(this,DisplayContact.class);
  i.putExtra("Contact_list", ContactLis);
  startActivity(i);

但我得到的问题,同时恢复它。

But I am getting problem while recovering it.

ArrayList<ContactBean> l1 = new ArrayList<ContactBean>();
Bundle wrapedReceivedList = getIntent().getExtras();
l1= wrapedReceivedList.getCharSequenceArrayList("Contact_list");

在这一点上我收到此错误:

At this point I am getting this error:

Type mismatch: cannot convert from ArrayList<CharSequence> to ArrayList<ContactBean>

我的ContactBean类实现Serializable也请您告诉我们为什么必须实现Serializable接口。

My ContactBean class implements Serializable please also tell why we have to implement serializable interface.

推荐答案

您可以传递一个的ArrayList&LT; E&GT; 以同样的方式,如果 Ë的类型是序列化

You can pass an ArrayList<E> the same way, if the E type is Serializable.

您会调用 putExtra(字符串名称,序列化值)意图来存储,而 getSerializableExtra(字符串名称)检索。

You would call the putExtra (String name, Serializable value) of Intent to store, and getSerializableExtra (String name) for retrieval.

例如:

ArrayList<String> myList = new ArrayList<String>();
intent.putExtra("mylist", myList);

在其他活动:

ArrayList<String> myList = (ArrayList<String>) getIntent().getSerializableExtra("mylist");

这篇关于如何通过的ArrayList&LT; CustomeObject&GT;从一个活动到另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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