【发布时间】:2020-03-27 21:47:47
【问题描述】:
我得到了一个带有双精度数组和另一个字符串的 JSON。我正在尝试使用相关方法创建一个 Parcelable 模型类。自动创建方法时,不会为双精度数组列表创建任何行。
我查找了相关的问题和信息,但令人惊讶的是,找不到任何信息。我还添加了一个应该提供帮助的 jar 文件:android-parcelable-intellij-plugin.jar。不知道它应该做什么,也找不到有关如何使用它的信息。
我的问题是我应该在方法中写什么才能在 List 中获取双精度数组。
代码:
public class Country implements Parcelable {
...
private List<String> timezones;
private List<Double> latlng;
protected Country(Parcel in) {
timezones = in.createStringArrayList();
this.latlng = new ArrayList<>(); // from jsonschema2pojo.org
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeStringList(timezones);
//nothing for the double array
}
public List<Double> getLatlng() {
return latlng;
}
public void setLatlng(List<Double> latlng) {
this.latlng = latlng;
}
public List<String> getTimezones() {
return timezones;
}
public void setTimezones(List<String> timezones) {
this.timezones = timezones;
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<Country> CREATOR = new Creator<Country>() {
@Override
public Country createFromParcel(Parcel in) {
return new Country(in);
}
@Override
public Country[] newArray(int size) {
return new Country[size];
}
};
}
...
谢谢。
【问题讨论】:
标签: java android arrays parcelable jsonschema2pojo