Android에서 Parcelable 클래스를 만들어서 Activities 사이에 이러한 객체의 ArrayList를 전달할 수 있습니다. 나는 매우 밀접하게 여기 StackOverflow (http://stackoverflow.com/questions/6201311/how-to-read-write-a-boolean-when-implementing-the-parcelable-interface)에서 발견 된 예제와 안드로이드 워드 프로세서 (http://developer.android.com/reference/android/os/Parcelable.html),하지만 난 필요한 정적 필드에 대한 오류가 발생하는 계속 크리에이터 : 필드 CREATOR 정적으로 선언 할 수 없습니다; 정적 필드는 정적 또는 최상위 수준 유형으로 만 선언 할 수 있습니다.안드로이드에서 Parcelable 클래스를 만드는 데 문제가 있습니다.
이 오류는 내 수업뿐만 아니라 Android 문서에서 직접 잘라내거나 붙여 넣기 한 클래스에서 발생합니다. 내가 알지 못하는 상황에 고유 한 뭔가가 있어야합니다 .... ?? 내 수업은 아래와 같습니다. 어떤 아이디어? 클래스가 다른 클래스 내부의 비 정적 선언되고처럼
감사합니다,
브라이언
public class ComplaintType implements Parcelable
{
// class data
private int groupID = 0;
private int id = 0;
private String description = "";
private boolean checked = false; // does this complaint type apply to this patient?
// constructors
public ComplaintType() {}
public ComplaintType(int _groupID, String desc, int _id, boolean ckd) {
this.groupID = _groupID;
this.description = desc;
this.id = _id;
this.checked = ckd;}
// getters/setters
public int getGroupID() {return groupID;}
public void setGroupID(int _groupID) { this.groupID = _groupID;}
public String getDesc() {return description;}
public void setDesc(String desc) {this.description = desc;}
public int getID() {return id;}
public void setID(int _id) {this.id = _id;}
public boolean isChecked() {return checked;}
public void setChecked(boolean ckd) {this.checked = ckd;}
// utility functions
public String toString() {return this.description;}
public void toggleChecked() {checked = !checked;}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(groupID);
dest.writeInt(id);
dest.writeString(description);
dest.writeByte((byte) (checked ? 1 : 0)); // convert byte to a boolean (1=true, 0=false)
}
public static final Parcelable.Creator<ComplaintType> CREATOR // <-- ERROR OCCURS HERE
= new Parcelable.Creator<ComplaintType>() {
public ComplaintType createFromParcel(Parcel in){
ComplaintType complaint = new ComplaintType();
complaint.setGroupID(in.readInt());
complaint.setID(in.readInt());
complaint.setDesc(in.readString());
complaint.setChecked(in.readByte() == 1); // store the boolean as a byte (1=true, 0=false)
return complaint;
}
@Override
public ComplaintType[] newArray(int size) {
return new ComplaintType[size];
}
};
}
Doh! 당신 말이 맞았습니다. 나는 다른 수업에서 선언했다. 최고 수준의 수업을 만들었습니다 ... 문제가 사라졌습니다. 나는 지금 바보 같아 보인다. 넛지 주셔서 감사합니다, 로렌스. –