2 csh 34 csh_34 于 2013.06.09 09:42 提问

发送一个 arraylist 到 parent activity

我想发送一个 arraylist 到 parent activity

private ArrayList<Receipt> receipts = new ArrayList<Receipt>();
 Intent data = new Intent();
 data. // what to do here?
setResult(RESULT_OK, data); 
//************************************

下面是简单的代码

public class Receipt {
    public String referenceNo;
    public byte[]   image;
    public String comments;
    public Date   createdOn;
    public Date   updatedOn;

如何在 intent 中添加,还有如何从 parent activity 里检索?

onActivityResult(final int requestCode, int resultCode, final Intent data)

2个回答

Baby_Bonnie
Baby_Bonnie   2013.06.13 11:25
已采纳
public class Receipt implements Serializable{
    public String referenceNo;
    public byte[]   image;
    public String comments;
    public long   createdOn;
    public long   updatedOn;
    //...
}

//Put the list in the intent
List<Receipt> list = ...
Intent data = new Intent();
data.putExtra("tag", list);

//Read the list from the intent:
list = (List<Receipt>) data.getSerializableExtra("tag");
cj6585256
cj6585256   2013.06.09 11:19

Receipt extends Parcelable才能传递

public void putParcelableArrayList(String key,
        ArrayList<? extends Parcelable> value) {}
Csdn user default icon
上传中...
上传图片
插入图片