[英]Pass ArrayList of Arrays (e.g. ArrayList<String[]>) to Intent
How do I pass an ArrayList of arrays to an intent in Android? 如何将数组的ArrayList传递给Android中的intent? I know you can pass an
ArrayList<String>
, but is it possible to pass an ArrayList<String[]>
? 我知道你可以传递一个
ArrayList<String>
,但是可以传递一个ArrayList<String[]>
吗?
It's possible, but you need to pass it as a Serializable
and you'll need to cast the result when you extract the extra. 这是可能的,但您需要将其作为
Serializable
传递,并且您需要在提取额外内容时转换结果。 Since ArrayList
implements Serializable
and String[]
is inherently serializable, the code is straightforward. 由于
ArrayList
实现了Serializable
而String[]
本质上是可序列化的,因此代码很简单。 To pass it: 通过它:
ArrayList<String[]> list = . . .;
Intent i = . . .;
i.putExtra("strings", list);
To retrieve it: 要检索它:
Intent i = . . .;
ArrayList<String[]> list = (ArrayList<String[]>) getSerializableExtra("strings");
You'll have to suppress (or live with) the unchecked conversion warning. 您必须抑制(或使用)未经检查的转换警告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.