捆绑的ArrayList< ArrayList的<整数GT;> [英] Bundle ArrayList <ArrayList<Integer>>

查看:117
本文介绍了捆绑的ArrayList< ArrayList的<整数GT;>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过一个的ArrayList< ArrayList的<整数GT;>地板通过捆绑其他活动?

感谢


解决方案

  

有没有办法通过一个ArrayList>楼层
  通过捆绑其他活动?


偏偏没有。

如果你有的ArrayList 没有嵌套它将与 putIntegerArrayList(键,值)和<$ C工作$ C> getIntegerArrayList(键)。

不过,可以肯定的是另一种方法(ES)。我将解释一种可能的方式。

您可以创建类,将实现Serializable接口,并在这个类只是创建领域和适当的getter。我给你基本的例子。然后,你将通过序列化通过活动。

 公共类DataHelper实现Serializable {   私人的ArrayList&LT; ArrayList的&LT;整数GT;&GT;地板;   公共DataHelper(ArrayList的&LT; ArrayList的&LT;整数GT;&GT;地板){
      this.floors =地板;
   }   公众的ArrayList&LT; ArrayList的&LT;整数GT;&GT;的GetList(){
      返回this.floors;
   }
}

保存到包:

 叠B =新包();
b.putSerializable(地板,新DataHelper(楼层));

和在目标活动检索:

  getIntent()getExtras()getSerializable(地板)。;

Is there a way to pass an ArrayList <ArrayList<Integer>> floors to another activity through Bundle?

Thanks

解决方案

Is there a way to pass an ArrayList > floors to another activity through Bundle?

Unfortunetly not.

If you would have ArrayList without nested it will work with putIntegerArrayList(key, value) and getIntegerArrayList(key).

But there is for sure another approach(es).I will explain you one possible way.

You can create class that will implement Serializable interface and in this class just create field and appropriate getter. I will give you basic example. Then you will pass Serializable through Activities.

public class DataHelper implements Serializable {

   private ArrayList<ArrayList<Integer>> floors;

   public DataHelper(ArrayList<ArrayList<Integer>> floors) {
      this.floors = floors;
   }

   public ArrayList<ArrayList<Integer>> getList() {
      return this.floors;
   }
}

Save it to Bundle:

Bundle b = new Bundle();
b.putSerializable("floors", new DataHelper(floors));

and retrieve in target Activity:

getIntent().getExtras().getSerializable("floors");

这篇关于捆绑的ArrayList&LT; ArrayList的&LT;整数GT;&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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