【发布时间】:2016-07-12 23:43:58
【问题描述】:
我有传递给标签的类别 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。如何按名称对类别进行排序?
【问题讨论】:
-
你能发布你的 'Category' 类,它实现了 Comparator 吗?
-
Categories 类不同,我问的 Category 也不同,看看你用过 List
而不是 List ...!! -
您想按类别名称对 List
进行排序吗? -
@vishalgajera 是的。
-
查看我的答案并按照它进行操作,将起作用
标签: java list sorting arraylist collections