通过意图传递LatLng的多维ArrayList [英] Pass multidimensional ArrayList of LatLng through intent
问题描述
我正在尝试使用putParcelableArrayListExtra ()
将ArrayList<ArrayList<LatLng>>
从一种意图传递到另一种意图,但是由于某种原因,它不喜欢我的列表.我用ArrayList<ArrayList<LatLng>> listOfStrokes = new ArrayList<>();
定义了数组列表,我想用
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. I define the array list with 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);
但是我得到
错误:(383,65)错误:类型不兼容:ArrayList>无法转换为ArrayList
Error:(383, 65) error: incompatible types: ArrayList> cannot be converted to ArrayList
错误.有没有办法传递这个物体?
error. Is there a way to pass this object?
推荐答案
首先-考虑使用Guava表来避免使用列表列表"模式.
First - consider using Guava tables to avoid a List of Lists pattern.
putParcelableArrayListExtra需要一个实现Parcelable的对象的列表. ArrayList没有. Arraylist实现了Serializable,因此下面的方法可以工作.
putParcelableArrayListExtra expects a List of objects that implements Parcelable. ArrayList does not. Arraylist implements Serializable, so the below will work.
ArrayList<ArrayList<LatLng>> listOfStrokes = new ArrayList<>();
Intent intent = new Intent(this, CreateFarm.class);
intent.putExtra("listOfStrokes", listOfStrokes);
这篇关于通过意图传递LatLng的多维ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!