小编use*_*360的帖子

如何在活动之间发送自定义对象数组?

我发现了许多发送ArrayList的地方,但是我需要能够将自定义对象"Card"的简单数组从活动A发送到B.我相信我已经以允许我的对象的方式创建了类从意图中作为额外传递.这是我的Parcelable类卡:

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

public class Card implements Parcelable{
   public String suit;
   public int value;
   public String color;

public Card(String suit, int value){
    this.suit = suit;
    this.value = value;

    if(suit == "hearts" || suit == "diamonds"){
        this.color = "red";
    }else{
        this.color = "black";
    }
}

public String toString(){
    String s = suit;
    return s;
}

 private Card(Parcel in) {
     value = in.readInt();
     color = in.readString();
     suit = in.readString();
    }

public int describeContents() {
    return 0;
}

public void writeToParcel(Parcel …
Run Code Online (Sandbox Code Playgroud)

java arrays android object android-intent

7
推荐指数
1
解决办法
3490
查看次数

标签 统计

android ×1

android-intent ×1

arrays ×1

java ×1

object ×1