我有各种RecyclerView
集(适配器和变量),但是RecyclerViews太多,所以我想将这些文件集成到一个文件中。
我认为Adapter
是不可能的,但我认为变量可以。
public class recyclerAData {
public Drawable drawable;
public String string1, string2, string3;
public recyclerAData (Drawable drawable, String string1, String string2, String string3) {
this.drawable = drawable;
this.string1 = string1;
this.string2 = string2;
this.string3 = string3;
}
}
public class recyclerBData {
public Drawable drawable1, drawable2;
public String string1, string2, string3;
public recyclerBData (Drawable drawable1, Drawable drawable2, String string1, String string2) {
this.drawable1 = drawable1;
this.drawable2 = drawable2;
this.string1 = string1;
this.string2 = string2;
}
}
举个例子,假设我们有这两个RecyclerView
数据,我想将这两个文件合为一个。
我认为这是可能的。
public class recyclerOneData {
public Drawable drawable1, drawable2;
public String string1, string2, string3;
public recyclerAData (Drawable drawable, String string1, String string2, String string3) {
this.drawable = drawable;
this.string1 = string1;
this.string2 = string2;
this.string3 = string3;
}
public recyclerBData (Drawable drawable1, Drawable drawable2, String string1, String string2) {
this.drawable1 = drawable1;
this.drawable2 = drawable2;
this.string1 = string1;
this.string2 = string2;
}
}
但是Android Studio说我需要返回类型,因此我无法继续。 有什么办法可以将它们组合在一起吗?等等,还有什么方法不仅可以集成变量,还可以集成适配器?
答案 0 :(得分:0)
我不确定您要在这里做什么。
但是您正在创建一个方法。您应该创建构造。
创建方法将始终需要返回类型。
public class recyclerOneData {
public Drawable drawable1, drawable2;
public String string1, string2, string3;
public recyclerOneData (Drawable drawable, String string1, String string2, String string3) {
this.drawable1 = drawable;
this.string1 = string1;
this.string2 = string2;
this.string3 = string3;
}
public recyclerOneData (Drawable drawable1, Drawable drawable2, String string1, String string2) {
this.drawable1 = drawable1;
this.drawable2 = drawable2;
this.string1 = string1;
this.string2 = string2;
}