【发布时间】:2021-01-19 13:57:41
【问题描述】:
我在使用 Volley 的 Recycler Adapter 中一次处理多个 JSON 对象(类)时遇到问题。我尝试了两种方法来解决这个问题,但未能为我的 Recycler 视图获取输出。
第一种方式:- 我创建了一个主类(父类),其中其他 JSON 类扩展了主类,并通过使用主类,我使用多态性一一调用了所有子类。 例如:-
Main.java
public class Main{
}
Model1.java
public class Model1 extends Main {
@SerializedName("$t")
@Expose
private String $t;
public String get$t() {
return $t;
}
public void set$t(String $t) {
this.$t = $t;
}
}
Model2.java
public class Model2 extends Main {
@SerializedName("$t")
@Expose
private String $t;
public String get$t() {
return $t;
}
public void set$t(String $t) {
this.$t = $t;
}
}
and during call I used
主要参考;
((Model1) (ref)).get$t();
((Model2) (ref)).get$t();
But, Failed to get all value(Please correct if I am worng in code)
and 2nd way:- Just making all the model class as inner class(static) of the main class and calling using
Main.Model1.get$t();
But did get output. Please suggest me any other way where I can use to get my expected output.
【问题讨论】:
标签: java android android-studio android-recyclerview android-volley