捆绑 ArrayList <ArrayList<Integer>> [英] Bundle ArrayList <ArrayList<Integer>>

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

问题描述

有没有办法传递 ArrayList <ArrayList<Integer>>地板通过捆绑到另一个活动?

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

谢谢

推荐答案

有没有办法将 ArrayList > 楼层传递给Bundle 中的另一项活动?

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

不幸的是没有.

如果您希望 ArrayList 没有嵌套,它将与 putIntegerArrayList(key, value)getIntegerArrayList(key) 一起使用.

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.

您可以创建将实现 Serializable 接口的类,并且在该类中只需创建字段和适当的 getter.我会给你一个基本的例子.然后你将通过活动传递 Serializable.

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;
   }
}

将其保存到捆绑包:

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

并在目标活动中检索:

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

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

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