我有傳遞給標籤的類別Arraylist。標籤獲取類別名稱並進行設置。如何對類別Arraylist進行排序?
private List<Category> mCategories;
private LayoutInflater mInflater;
public LeftMenuAdapter(Context context, List<Category> categories) {
mCategories = categories;
mInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
Category category = mCategories.get(position - 3);
holder.label.setText(category.getName());
分類等級:
public class Category implements Parcelable {
private List<String> images;
private String name;
public List<String> getImages() {
return this.images;
}
public void setImages(List<String> images) {
this.images = images;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
protected Category(Parcel in) {
if (in.readByte() == 0x01) {
images = new ArrayList<String>();
in.readList(images, String.class.getClassLoader());
} else {
images = null;
}
name = in.readString();
}
@Override
public int describeContents() {
return 2;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
if (images == null) {
dest.writeByte((byte) (0x00));
} else {
dest.writeByte((byte) (0x01));
dest.writeList(images);
}
dest.writeString(name);
}
public static final Parcelable.Creator<Category> CREATOR = new Parcelable.Creator<Category>() {
@Override
public Category createFromParcel(Parcel in) {
return new Category(in);
}
@Override
public Category[] newArray(int size) {
return new Category[size];
}
};
}
我使用的比較,但它說Cannot resolve symbol sort
。我怎樣才能按名稱對類別進行排序?
你可以發表你的 '類別' 類,它具有實現比較? –
分類類是不同的,我問的類別也不同,看你有沒有使用名單不是名單 ... !! –
您想按類別名稱對列表進行排序嗎? –