简体   繁体   English

通过意图传递LatLng的多维ArrayList

[英]Pass multidimensional ArrayList of LatLng through intent

I am trying to pass an ArrayList<ArrayList<LatLng>> from one intent to another using putParcelableArrayListExtra () but for some reason it doesn't like my list. 我试图使用putParcelableArrayListExtra ()ArrayList<ArrayList<LatLng>>从一种意图传递到另一种意图,但是由于某种原因,它不喜欢我的列表。 I define the array list with ArrayList<ArrayList<LatLng>> listOfStrokes = new ArrayList<>(); 我用ArrayList<ArrayList<LatLng>> listOfStrokes = new ArrayList<>();定义数组列表ArrayList<ArrayList<LatLng>> listOfStrokes = new ArrayList<>(); and I am trying to pass it with 我试图通过

ArrayList<ArrayList<LatLng>> listOfStrokes = new ArrayList<>();

Intent intent = new Intent(this, CreateFarm.class);

intent.putParcelableArrayListExtra("listOfStrokes", listOfStrokes);

but I am getting a 但我得到一个

Error:(383, 65) error: incompatible types: ArrayList> cannot be converted to ArrayList 错误:(383,65)错误:不兼容的类型:ArrayList>无法转换为ArrayList

error. 错误。 Is there a way to pass this object? 有没有办法传递这个物体?

First - consider using Guava tables to avoid a List of Lists pattern. 首先-考虑使用Guava表来避免使用List of Lists模式。

putParcelableArrayListExtra expects a List of objects that implements Parcelable. putParcelableArrayListExtra需要一个实现Parcelable的对象的列表。 ArrayList does not. ArrayList没有。 Arraylist implements Serializable, so the below will work. Arraylist实现了Serializable,因此下面的方法可以工作。

ArrayList<ArrayList<LatLng>> listOfStrokes = new ArrayList<>();

Intent intent = new Intent(this, CreateFarm.class);

intent.putExtra("listOfStrokes", listOfStrokes);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM