I have class ITEM and I want to pass array (Item[] items) of this class from ACTIVITY to FRAGMENT. Activity and fragment use Android Annotations.
public class Item implements Parcelable {
public int id;
public String code;
public Item() {
}
public Item(int id, String code) {
this.id = id;
this.code = code;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
protected Item(Parcel in) {
id = in.readInt();
code = in.readString();
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeString(code);
}
@SuppressWarnings("unused")
public static final Creator<Item> CREATOR = new Creator<Item>() {
@Override
public Item createFromParcel(Parcel in) {
return new Item(in);
}
@Override
public Item[] newArray(int size) {
return new Item[size];
}
};
}
Now I do it old way - I do not use parcelable, because I do not have to, but it seems that I can´t pass same argument to fragment with Android Annotations (I may be wrong).
Activity:
new ItemFragment(items)
Fragment:
public class ItemFragment extends Fragment {
public ItemFragment (Item[] items) {
this.items= items;
}
}