gpt4 book ai didi

java - 通过可分割的槽 Activity 获取特定领域

转载 作者:行者123 更新时间:2023-12-02 12:44:14 25 4
gpt4 key购买 nike

我更改了类接口(interface)以使用 Parcelable,因为我需要通过一些 Activity 传递对象来完成工作。

所以我已经实现了一个可包裹类(使用一个可以实现这一点的插件),如下所示:

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];
}
};
}

在我的 Activity 中,我创建并填充我的照片的构造函数,如下所示:

  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 Activity ,在该 Activity 中我需要检索可包裹并获取特定数据(在本例中只是 uri)

这就是我所做的:

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

getImage() 不存在,我不知道如何检索特定照片对象的可分割字段,有帮助吗?还有其他方法可以使用我不知道的 Parcelable 来做到这一点吗?

非常感谢

最佳答案

正如我所见,您的数据类没有 getter 和 setter ,因此请尝试右键单击该类并选择 create setter 和 getters 。然后使用这些 getter 来获取您的数据

例如。如果你想有时间

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

关于java - 通过可分割的槽 Activity 获取特定领域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44828280/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com