0

我在自定义数组列表中有一个对象为“finaljsoncontent”,现在我正在尝试将这个“finaljsoncontent”数组传递给另一个活动,我也尝试过getter和setter,以及捆绑,但我不能,帮助我如何做这个。提前致谢。

4

3 回答 3

0

You could try implementing Parcelable, then you can pass it in a bundle. You will need to reduce your object to mostly primitive types to do this. Otherwise you can extend the Application class and store it there. You would retrieve that using the call to getApplicationContext(). Or, of course, you could always create some sort of static globals class that all of your classes can reference.

Here is one of my implementations of parcelable..

package warrior.mail.namespace;

import android.os.Parcel;
import android.os.Parcelable;

public class JView implements Parcelable {
    public String subject;
    public String from;
    public boolean unread;
    public String body;
    public int inboxIndex;
    private long id;
    public static final Parcelable.Creator<JView> CREATOR = new Parcelable.Creator<JView>() {

        public JView createFromParcel(Parcel in) {
            return new JView(in);
        }

        public JView[] newArray(int size) {
            return new JView[size];
        }

    };

    public JView(){
        body = "";
    }

    public JView(String subject,String from,boolean unread){
        body = "";
        this.subject = subject;
        this.from = from;
        this.unread = unread;
    }

    public JView(Parcel parcel){
        subject = parcel.readString();
        from = parcel.readString();
        body = parcel.readString();
        unread = parcel.createBooleanArray()[0];
        inboxIndex = parcel.readInt();
    }

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

    @Override
    public void writeToParcel(Parcel out, int arg1) {
        out.writeString(subject);
        out.writeString(from);
        out.writeString(body);
        boolean[] array = new boolean[] {unread};
        out.writeBooleanArray(array);
        out.writeInt(inboxIndex);
    }

    public void setIndex(int index){
        inboxIndex = index;
    }

    public void setUnread(boolean arg){
        unread = arg;
    }

    public void setContent(String content){
        body = content;
    }

    public void setSubject(String subject){
        this.subject = subject;
    }

    public void setFrom(String f){
        from = f;
    }

    public void setId(long arg){
        id = arg;
    }

    public long getId(){
        return id;
    }

    public void updateIndex(){

    }
}
于 2012-07-31T16:43:31.483 回答
0

您可以使您的类Parcelable(特定于android)或使其像在java中一样可序列化(只需使用您的类编写实现Serializable)

于 2012-07-31T16:52:18.320 回答
0

看看这个:如何在 Android 上将对象从一个活动传递到另一个活动?

你的类“JSonKey”应该实现parcealable或serializable,以便Android可以将它从一个活动“发送”到另一个活动。

于 2012-07-31T16:46:49.777 回答