2017-06-29 6 views
0

私は自分の仕事を完了させるためにいくつかのアクティビティをオブジェクトに渡す必要があるので、私はクラスのインターフェイスをparcelableに変更しました。特定のフィールドをparcelableなトラフのアクティビティで取得する

だから私はそのような(というんプラグインを使用して)parcelableクラス実装されています:私は作る私のactivite上

public class Photo implements Parcelable { 
    private int id; 
    private Uri image; 
    private byte[] cropedImage; 
    private String path; 
    private Double lat; 
    private Double lon; 
    private Double alt; 
    private String time; 

    public Photo() { 
    } 


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

    public Photo(Uri image, Double lat, Double lon, Double alt, String time) { 
     this.image = image; 
     this.lat = lat; 
     this.lon = lon; 
     this.alt = alt; 
     this.time = time; 
    } 

    @Override 
    public void writeToParcel(Parcel dest, int flags) { 
     dest.writeInt(this.id); 
     dest.writeParcelable(this.image, flags); 
     dest.writeByteArray(this.cropedImage); 
     dest.writeString(this.path); 
     dest.writeValue(this.lat); 
     dest.writeValue(this.lon); 
     dest.writeValue(this.alt); 
     dest.writeString(this.time); 
    } 

    protected Photo(Parcel in) { 
     this.id = in.readInt(); 
     this.image = in.readParcelable(Uri.class.getClassLoader()); 
     this.cropedImage = in.createByteArray(); 
     this.path = in.readString(); 
     this.lat = (Double) in.readValue(Double.class.getClassLoader()); 
     this.lon = (Double) in.readValue(Double.class.getClassLoader()); 
     this.alt = (Double) in.readValue(Double.class.getClassLoader()); 
     this.time = in.readString(); 
    } 

    public static final Creator<Photo> CREATOR = new Creator<Photo>() { 
     @Override 
     public Photo createFromParcel(Parcel source) { 
      return new Photo(source); 
     } 

     @Override 
     public Photo[] newArray(int size) { 
      return new Photo[size]; 
     } 
    }; 
} 

をし、このように私の写真のコンストラクタ埋める:

Photo photo = new Photo(image,location.getLatitude(),location.getLongitude(),location.getAltitude(),data); 

     Intent i = new Intent(CameraCapture.this, CropImage.class); 
     i.putExtra("Photo",photo); 

私はそれをCropImageアクティビティに渡します。そのアクティビティでは、パーセルブルを取得して特定のデータ(この場合はURIのみ)を取得する必要があります

これは私が行って何です:

photo = getIntent().getExtras().getParcelable("Photo"); 
uri = photo.getImage(); 

のgetImage()が存在しない、私は、特定の写真オブジェクトの任意のヘルプをparcelableフィールドをretriveする方法がわかりませんか?私が考え出していないパーセルブルを使ってこれを行う別の方法がありますか?

どうもありがとう

答えて

1

私はあなたのデータクラスは、ゲッターとセッターを持っているので、そのクラス内で右クリックをしてみてくださいとセッターとゲッターを作成選択しません見ての通り。これらのゲッターを使用してデータを取得してください。

例:あなたが時間を得たい場合は、

private String time; 
public String getTime(){  
    return time; 
} 
+0

ああ、それはパーセルブルとは違っていた – afcosta007

関連する問題