1

在我的项目中,我想将数据列表从一项活动发送到另一项活动。

Bundle bundle = new Bundle();
bundle.putString("C/V", "V");
bundle.putString("mode", "vo");
4

1 回答 1

3

最后,我在课堂上完成了使用 parcelable

public class Channel implements Serializable, Parcelable {

/**  */
private static final long serialVersionUID = 4861597073026532544L;

private String cid;
private String uniqueID;
private String name;
private String logo;
private String thumb;


/**
 * @return the cid
 */
public String getCid() {
    return cid;
}

/**
 * @param cid
 *            the cid to set
 */
public void setCid(String cid) {
    this.cid = cid;
}

/**
 * @return the uniqueID
 */
public String getUniqueID() {
    return uniqueID;
}

/**
 * @param uniqueID
 *            the uniqueID to set
 */
public void setUniqueID(String uniqueID) {
    this.uniqueID = uniqueID;
}

/**
 * @return the name
 */
public String getName() {
    return name;
}

/**
 * @param name
 *            the name to set
 */
public void setName(String name) {
    this.name = name;
}

/**
 * @return the logo
 */
public String getLogo() {
    return logo;
}

/**
 * @param logo
 *            the logo to set
 */
public void setLogo(String logo) {
    this.logo = logo;
}

/**
 * @return the thumb
 */
public String getThumb() {
    return thumb;
}

/**
 * @param thumb
 *            the thumb to set
 */
public void setThumb(String thumb) {
    this.thumb = thumb;
}


public Channel(Parcel in) {
    super();
    readFromParcel(in);
}

public static final Parcelable.Creator<Channel> CREATOR = new Parcelable.Creator<Channel>() {
    public Channel createFromParcel(Parcel in) {
        return new Channel(in);
    }

    public Channel[] newArray(int size) {

        return new Channel[size];
    }

};

public void readFromParcel(Parcel in) {
    String[] result = new String[23];
    in.readStringArray(result);

    this.cid = result[0];
    this.uniqueID = result[1];
    this.name = result[2];
    this.logo = result[3];
    this.thumb = result[4];


}

public int describeContents() {
    return 0;
}

public void writeToParcel(Parcel dest, int flags) {
    dest.writeStringArray(new String[] { this.cid, this.uniqueID,
            this.name, this.logo, this.thumb});

}}

在 ActivityA 中这样使用来发送数据。

Bundle bundle = new Bundle();
bundle.putParcelableArrayList("channel",(ArrayList<Channel>) channels);
Intent intent = new Intent(ActivityA.this,ActivityB.class);
intent.putExtras(bundle);
startActivity(intent);

在 ActivityB 中像这样使用来获取数据。

Bundle getBundle = this.getIntent().getExtras();
List<Channel> channelsList = getBundle.getParcelableArrayList("channel");
于 2013-08-10T18:42:57.710 回答