有没有办法通过一个的ArrayList< ArrayList的<整数GT;>地板
通过捆绑其他活动?
感谢
解决方案有没有办法通过一个ArrayList>楼层 通过捆绑其他活动?
偏偏没有。
如果你有的ArrayList
没有嵌套它将与 putIntegerArrayList(键,值)
和 getIntegerArrayList(键)。
不过,可以肯定的是另一种方法(ES)。我将解释一种可能的方式。
您可以创建类,将实现Serializable接口,并在这个类只是创建领域和适当的getter。我给你基本的例子。然后,你将通过序列化通过活动。
公共类DataHelper实现Serializable { 私人的ArrayList< ArrayList的<整数GT;>地板; 公共DataHelper(ArrayList的< ArrayList的<整数GT;>地板){ this.floors =地板; } 公众的ArrayList< ArrayList的<整数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");