我想用Collections.sort
方法对类别arraylist进行排序,但没有运气。如何在实现Parcelable时排序ArrayList
这里是我的代码:
public class Categories implements Parcelable {
private ArrayList<Category> category;
private Recent recent;
public ArrayList<Category> getCategories() {
return this.category;
}
public void setCategory(ArrayList<Category> category) {
this.category = category;
}
public Recent getRecent() {
return this.recent;
}
public void setRecent(Recent recent) {
this.recent = recent;
}
protected Categories(Parcel in) {
if (in.readByte() == 0x01) {
category = new ArrayList<Category>();
in.readList(category, Category.class.getClassLoader());
} else {
category = null;
}
recent = (Recent) in.readValue(Recent.class.getClassLoader());
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
if (category == null) {
dest.writeByte((byte) (0x00));
} else {
dest.writeByte((byte) (0x01));
dest.writeList(category);
}
dest.writeValue(recent);
}
public static final Parcelable.Creator<Categories> CREATOR = new Parcelable.Creator<Categories>() {
@Override
public Categories createFromParcel(Parcel in) {
return new Categories(in);
}
@Override
public Categories[] newArray(int size) {
return new Categories[size];
}
};
}
你有没有尝试在你的类别类实现可比较? https://docs.oracle.com/javase/tutorial/collections/interfaces/order.html – RubioRic
@ user2004685我从来没有使用'delegates'。你能帮助我吗? –
@ user2004685我不熟悉Android编程,但为什么不呢?你能链接一些相关的信息吗? – RubioRic