我有一个“DayForecast”模型,其中包含另一个模型“WeatherCondition”的 SparseArray,它每 3 小时有几个关于天气条件的信息(所以那里有 8 个天气条件模型)。
DayForecast.java:
public class DayForecast implements Serializable {
private String mDate;
private String mDescription;
private SparseArray<WeatherCondition> mWeatherConditions = new SparseArray<WeatherCondition>();
public WeatherCondition getWeatherCondition(int timeInHours) {
// return null if no weather condition was set
WeatherCondition weatherCondition = mWeatherConditions.get(timeInHours);
// or you could add some other logic here, if you would want the next available weather condition,
// but make sure to reflect that in the method name
return weatherCondition;
}
public void setWeatherCondition(int timeInHours, WeatherCondition weatherCondition) {
mWeatherConditions.append(timeInHours, weatherCondition);
}
public String getmDate() {
return mDate;
}
public void setmDate(String mDate) {
this.mDate = mDate;
}
public String getmDescription() {
return mDescription;
}
public void setmDescription(String mDescription) {
this.mDescription = mDescription;
}
}
WeatherCondition.java
public class WeatherCondition {
public int getTime() {
return mTime;
}
public void setTime(int time) {
this.mTime = time;
}
private int mTime;
private String mTemperature;
private String mWindSpeed;
private String mDirection;
public WeatherCondition(int time,String temperature, String windSpeed, String direction) {
mTime = time;
mTemperature = temperature;
mWindSpeed = windSpeed;
mDirection = direction;
}
// ... setter and getter methods ...
public String getmTemperature() {
return mTemperature;
}
public void setmTemperature(String mTemperature) {
this.mTemperature = mTemperature;
}
public String getmWindSpeed() {
return mWindSpeed;
}
public void setmWindSpeed(String mWindSpeed) {
this.mWindSpeed = mWindSpeed;
}
public String getmDirection() {
return mDirection;
}
public void setmDirection(String mDirection) {
this.mDirection = mDirection;
}
}
片段.java:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle args = getArguments();
dayForecast = (DayForecast) args.getSerializable("object");
}
我想做的是在我的片段中构建 WeatherConditions 的 listView。
我成功检索到传递给我的片段的 DayForecast 对象的其他数据,但我正在努力检索天气条件并构建 listView。
有人能帮助我吗?
谢谢