0

这就是我创建数组列表并将其传递给意图的方式

private ArrayList<Words> words = new ArrayList<Words>();
Intent intent = new Intent(Game.this,removeWords.getClass());
intent.putParcelableArrayListExtra("LIST OF WORDS", (ArrayList<? extends Parcelable>) words);
startActivity(intent);

这就是我在子活动中获取这些数据的方式

private List<Words> words;
words = new ArrayList<Words>();
words = getIntent().getParcelableArrayListExtra("LIST OF WORDS");

但问题是,我收到下面提到的错误:

绑定不匹配:Intent 类型的通用方法 getParcelableArrayListExtra(String) 不适用于参数 (String)。

推断的类型 Words 不是有界的有效替代品parameter<T extends parcelable>

我正在尝试传递该数组列表,所以我不介意它是它putParcelableArrayListExtra还是其他方法。我发现这是在 SO question 中完成这项工作的方法,这就是我使用它的原因。

那么,我怎样才能摆脱这个异常呢?

4

1 回答 1

0

如果您想发送对象的 ArrayList,那么您的类必须实现 Parcelable 或 Serializable 接口。

查看这些在活动之间发送自定义对象的好教程

http://androidideasblog.blogspot.in/2010/02/passing-list-of-objects-between.html

http://androidideasblog.blogspot.in/2010/02/passing-list-of-objects-between.html

http://www.anddev.org/novice-tutorials-f8/simple-tutorial-passing-arraylist-across-activities-t9996.html

于 2013-07-31T09:27:40.920 回答