我正在遵循本教程:
Android Studio Tutorial - Expandable RecyclerView
成功。
但是我想要这样更丰富多彩:
Group中显示了一些漂亮的图像。
请帮助我,谢谢。
我的子班是Product.class
public class Product implements Parcelable{
public final String name;
public final int icon;
public Product(String name, int icon) {
this.name = name;
this.icon = icon;
}
protected Product(Parcel in) {
name = in.readString();
icon = in.readInt();
}
public static final Creator<Product> CREATOR = new Creator<Product>() {
public Product createFromParcel(Parcel in) {
return new Product(in);
}
public Product[] newArray(int size) {
return new Product[size];
}
};
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeInt(icon);
}
}
我的组是Company.class:
public class Company extends ExpandableGroup<Product>{
public Company(String title, List<Product> items) {
super(title, items);
}
}
CompanyViewHolder.java:
public class CompanyViewHolder extends GroupViewHolder {
TextView mTextView;
ImageView arrow;
private ImageView icon;
public CompanyViewHolder(View itemView) {
super(itemView);
mTextView = itemView.findViewById(R.id.textView);
arrow = itemView.findViewById(R.id.arraw);
icon = itemView.findViewById(R.id.company_icon);
}
public void bind(Company company){
mTextView.setText(company.getTitle());
icon.setImageResource ...??
}
答案 0 :(得分:0)
在该示例中检查GenreDataFactory.java
public class GenreDataFactory {
public static List<Genre> makeGenres() {
return Arrays.asList(makeRockGenre(),
makeJazzGenre(),
makeClassicGenre(),
makeSalsaGenre(),
makeBluegrassGenre());
}
public static List<MultiCheckGenre> makeMultiCheckGenres() {
return Arrays.asList(makeMultiCheckRockGenre(),
makeMultiCheckJazzGenre(),
makeMultiCheckClassicGenre(),
makeMultiCheckSalsaGenre(),
makeMulitCheckBluegrassGenre());
}
public static List<SingleCheckGenre> makeSingleCheckGenres() {
return Arrays.asList(makeSingleCheckRockGenre(),
makeSingleCheckJazzGenre(),
makeSingleCheckClassicGenre(),
makeSingleCheckSalsaGenre(),
makeSingleCheckBluegrassGenre());
}
public static Genre makeRockGenre() {
return new Genre("Rock", makeRockArtists(), R.drawable.ic_electric_guitar);
}
public static MultiCheckGenre makeMultiCheckRockGenre() {
return new MultiCheckGenre("Rock", makeRockArtists(), R.drawable.ic_electric_guitar);
}
public static SingleCheckGenre makeSingleCheckRockGenre() {
return new SingleCheckGenre("Rock", makeRockArtists(), R.drawable.ic_electric_guitar);
}
public static List<Artist> makeRockArtists() {
Artist queen = new Artist("Queen", true);
Artist styx = new Artist("Styx", false);
Artist reoSpeedwagon = new Artist("REO Speedwagon", false);
Artist boston = new Artist("Boston", true);
return Arrays.asList(queen, styx, reoSpeedwagon, boston);
}
public static Genre makeJazzGenre() {
return new Genre("Jazz", makeJazzArtists(), R.drawable.ic_saxaphone);
}
public static MultiCheckGenre makeMultiCheckJazzGenre() {
return new MultiCheckGenre("Jazz", makeJazzArtists(), R.drawable.ic_saxaphone);
}
public static SingleCheckGenre makeSingleCheckJazzGenre() {
return new SingleCheckGenre("Jazz", makeJazzArtists(), R.drawable.ic_saxaphone);
}
public static List<Artist> makeJazzArtists() {
Artist milesDavis = new Artist("Miles Davis", true);
Artist ellaFitzgerald = new Artist("Ella Fitzgerald", true);
Artist billieHoliday = new Artist("Billie Holiday", false);
return Arrays.asList(milesDavis, ellaFitzgerald, billieHoliday);
}
public static Genre makeClassicGenre() {
return new Genre("Classic", makeClassicArtists(), R.drawable.ic_violin);
}
public static MultiCheckGenre makeMultiCheckClassicGenre() {
return new MultiCheckGenre("Classic", makeClassicArtists(), R.drawable.ic_violin);
}
public static SingleCheckGenre makeSingleCheckClassicGenre() {
return new SingleCheckGenre("Classic", makeClassicArtists(), R.drawable.ic_violin);
}
public static List<Artist> makeClassicArtists() {
Artist beethoven = new Artist("Ludwig van Beethoven", false);
Artist bach = new Artist("Johann Sebastian Bach", true);
Artist brahms = new Artist("Johannes Brahms", false);
Artist puccini = new Artist("Giacomo Puccini", false);
return Arrays.asList(beethoven, bach, brahms, puccini);
}
public static Genre makeSalsaGenre() {
return new Genre("Salsa", makeSalsaArtists(), R.drawable.ic_maracas);
}
public static MultiCheckGenre makeMultiCheckSalsaGenre() {
return new MultiCheckGenre("Salsa", makeSalsaArtists(), R.drawable.ic_maracas);
}
public static SingleCheckGenre makeSingleCheckSalsaGenre() {
return new SingleCheckGenre("Salsa", makeSalsaArtists(), R.drawable.ic_maracas);
}
public static List<Artist> makeSalsaArtists() {
Artist hectorLavoe = new Artist("Hector Lavoe", true);
Artist celiaCruz = new Artist("Celia Cruz", false);
Artist willieColon = new Artist("Willie Colon", false);
Artist marcAnthony = new Artist("Marc Anthony", false);
return Arrays.asList(hectorLavoe, celiaCruz, willieColon, marcAnthony);
}
public static Genre makeBluegrassGenre() {
return new Genre("Bluegrass", makeBluegrassArtists(), R.drawable.ic_banjo);
}
public static MultiCheckGenre makeMulitCheckBluegrassGenre() {
return new MultiCheckGenre("Bluegrass", makeBluegrassArtists(), R.drawable.ic_banjo);
}
public static SingleCheckGenre makeSingleCheckBluegrassGenre() {
return new SingleCheckGenre("Bluegrass", makeBluegrassArtists(), R.drawable.ic_banjo);
}
public static List<Artist> makeBluegrassArtists() {
Artist billMonroe = new Artist("Bill Monroe", false);
Artist earlScruggs = new Artist("Earl Scruggs", false);
Artist osborneBrothers = new Artist("Osborne Brothers", true);
Artist johnHartford = new Artist("John Hartford", false);
return Arrays.asList(billMonroe, earlScruggs, osborneBrothers, johnHartford);
}
}