Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从ArrayList传递数据<;项目>;Android中的其他活动?_Android_List_Listview_Android Intent_Arraylist - Fatal编程技术网

从ArrayList传递数据<;项目>;Android中的其他活动?

从ArrayList传递数据<;项目>;Android中的其他活动?,android,list,listview,android-intent,arraylist,Android,List,Listview,Android Intent,Arraylist,可能重复: 我已经尝试过使用putExtra(),但没有效果 当我使用putExtra()时,出现了语法错误。唯一的方法(似乎)是将选定的全部数据转换为字符串。但问题是,我只需要显示部分数据,而不是全部数据。因此,我认为这不是办法 我想做的是发送一个ArrayList数据。第一个活动是程序在数组中搜索数据,第二个活动是显示部分数据 我需要发送列表视图的数据onClick()。我需要数据在ArrayList中 在任何人回答或评论这个问题之前,请先看看我的声誉。所以有这么多的名声,我想你知道我是新

可能重复:

我已经尝试过使用
putExtra()
,但没有效果

当我使用
putExtra()
时,出现了语法错误。唯一的方法(似乎)是将选定的全部数据转换为字符串。但问题是,我只需要显示部分数据,而不是全部数据。因此,我认为这不是办法

我想做的是发送一个
ArrayList
数据。第一个活动是程序在数组中搜索数据,第二个活动是显示部分数据

我需要发送
列表视图
的数据
onClick()
。我需要数据在
ArrayList


在任何人回答或评论这个问题之前,请先看看我的声誉。所以有这么多的名声,我想你知道我是新来的。在否决表决之前,请考虑这一点。

假设您有这样一个类,它实现了
Parcelable

public class CustomParcelableClass implements Parcelable {
    public String string;
    public int i;

    @Override
    public int describeContents() {
        return hashCode();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(i);
        dest.writeString(string);
    }

            private Item(Parcel in) {
             string= in.readString();
            }
}
然后你做出一个
意图
,如下所示:

ArrayList<CustomParcelableClass> myParcelableList = 
          new ArrayList<CustomParcelableClass>();
myParcelableList.add(...);
...
yourIntent.putParcelableArrayListExtra(LIST, myParcelableList);
在第二个类中,在类似于
onNewIntent(Intent i)
的方法中,通过

ArrayList<CustomParcelableClass> myParcelableList = 
        i.getExtras().getParcelableArrayList(LIST);
ArrayList myParcelableList=
i、 getExtras().getParcelableArrayList(列表);

我不知道为什么这对你不起作用。

这已经在至少五个其他问题中详细讨论过了(其中一个是这样的问题,它链接到其他问题);从谷歌开始。。。那么,为什么不将
项目
设为Parcelable
?@ChristiaandeJong我尝试过这样做,但当我使用Parcelable时,我无法显示结果。我不知道我做错了什么谢谢你的回复。我已经试着实现你所说的,但不知怎么的,当程序想要转到其他活动时,程序将由于错误而崩溃
Javabinder!!!活页夹事务失败。应该没有内存问题,对吗?毕竟传递的数据只是一行文本。@akemalFirdaus与您最初的问题无关。谷歌搜索,你会发现的。谢谢你,终于做到了。你的答案中缺少了一个方法。我已经编辑过了。
ArrayList<CustomParcelableClass> myParcelableList = 
        i.getExtras().getParcelableArrayList(LIST);