Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // this is model class
- package ali.arshad.soomro.openweathermap.androidsdk;
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.List;
- import com.google.gson.annotations.SerializedName;
- public class WeatherForecastInfo implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- private String cod;
- private Double message;
- private City city;
- private Integer cnt;
- private ListItem listItem;
- private List<ListItem> list = new ArrayList<ListItem>();
- /**
- * @return the listItem
- */
- public ListItem getListItem() {
- return listItem;
- }
- /**
- * @param listItem the listItem to set
- */
- public void setListItem(ListItem listItem) {
- this.listItem = listItem;
- }
- public String getCod() {
- return cod;
- }
- public void setCod(String cod) {
- this.cod = cod;
- }
- public Double getMessage() {
- return message;
- }
- public void setMessage(Double message) {
- this.message = message;
- }
- public City getCity() {
- return city;
- }
- public void setCity(City city) {
- this.city = city;
- }
- public Integer getCnt() {
- return cnt;
- }
- public void setCnt(Integer cnt) {
- this.cnt = cnt;
- }
- public List<ListItem> getList() {
- return list;
- }
- public void setList(List<ListItem> list) {
- this.list = list;
- }
- public class City implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- private Integer id;
- private String name;
- @SerializedName("coord")
- private Coordinates coordinates;
- private String country;
- private Integer population;
- private Sys sys;
- public Integer getId() {
- return id;
- }
- public void setId(Integer id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public Coordinates getCoordinates() {
- return coordinates;
- }
- public void setCoordinates(Coordinates coordinates) {
- this.coordinates = coordinates;
- }
- public String getCountry() {
- return country;
- }
- public void setCountry(String country) {
- this.country = country;
- }
- public Integer getPopulation() {
- return population;
- }
- public void setPopulation(Integer population) {
- this.population = population;
- }
- public Sys getSys() {
- return sys;
- }
- public void setSys(Sys sys) {
- this.sys = sys;
- }
- public class Coordinates implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- @SerializedName("lon")
- private Double longitude;
- @SerializedName("lat")
- private Double latitude;
- public Double getLongitude() {
- return longitude;
- }
- public void setLongitude(Double longitude) {
- this.longitude = longitude;
- }
- public Double getLatitude() {
- return latitude;
- }
- public void setLatitude(Double latitude) {
- this.latitude = latitude;
- }
- }
- public class Sys implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- private Integer population;
- public Integer getPopulation() {
- return population;
- }
- public void setPopulation(Integer population) {
- this.population = population;
- }
- }
- }
- public class ListItem implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- @SerializedName("dt")
- private Long dateTime;
- @SerializedName("temp")
- private Temperature temperature;
- private Double pressure;
- private Integer humidity;
- private List<Weather> weather = new ArrayList<Weather>();
- private Double speed;
- @SerializedName("deg")
- private Integer degree;
- private Integer clouds;
- public Long getDateTime() {
- return dateTime;
- }
- public void setDateTime(Long dateTime) {
- this.dateTime = dateTime;
- }
- public Temperature getTemperature() {
- return temperature;
- }
- public void setTemperature(Temperature temperature) {
- this.temperature = temperature;
- }
- public Double getPressure() {
- return pressure;
- }
- public void setPressure(Double pressure) {
- this.pressure = pressure;
- }
- public Integer getHumidity() {
- return humidity;
- }
- public void setHumidity(Integer humidity) {
- this.humidity = humidity;
- }
- public List<Weather> getWeather() {
- return weather;
- }
- public void setWeather(List<Weather> weather) {
- this.weather = weather;
- }
- public Double getSpeed() {
- return speed;
- }
- public void setSpeed(Double speed) {
- this.speed = speed;
- }
- public Integer getDegree() {
- return degree;
- }
- public void setDegree(Integer degree) {
- this.degree = degree;
- }
- public Integer getClouds() {
- return clouds;
- }
- public void setClouds(Integer clouds) {
- this.clouds = clouds;
- }
- public class Temperature implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- private Double day;
- private Double min;
- private Double max;
- private Double night;
- @SerializedName("eve")
- private Double evening;
- @SerializedName("morn")
- private Double morning;
- public Double getDay() {
- return day;
- }
- public void setDay(Double day) {
- this.day = day;
- }
- public Double getMin() {
- return min;
- }
- public void setMin(Double min) {
- this.min = min;
- }
- public Double getMax() {
- return max;
- }
- public void setMax(Double max) {
- this.max = max;
- }
- public Double getNight() {
- return night;
- }
- public void setNight(Double night) {
- this.night = night;
- }
- public Double getEvening() {
- return evening;
- }
- public void setEvening(Double evening) {
- this.evening = evening;
- }
- public Double getMorning() {
- return morning;
- }
- public void setMorning(Double morning) {
- this.morning = morning;
- }
- }
- public class Weather implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- private Integer id;
- private String main;
- private String description;
- private String icon;
- public Integer getId() {
- return id;
- }
- public void setId(Integer id) {
- this.id = id;
- }
- public String getMain() {
- return main;
- }
- public void setMain(String main) {
- this.main = main;
- }
- public String getDescription() {
- return description;
- }
- public void setDescription(String description) {
- this.description = description;
- }
- public String getIcon() {
- return icon;
- }
- public void setIcon(String icon) {
- this.icon = icon;
- }
- }
- }
- }
- // and in my DemoActivity class
- protected List<WeatherForecastInfo.ListItem.Weather> list = null;
- protected ArrayAdapter<WeatherForecastInfo.ListItem.Weather> adapter = null;
- //and in onCreate I have
- mapUtil = WeatherUtil.newInstance();
- button.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- new AsyncTask<String, Void, WeatherForecastInfo>() {
- @Override
- protected void onPreExecute() {
- progressDialog = new ProgressDialog(DemoActivity.this);
- progressDialog.setTitle("Wait...");
- progressDialog.setMessage("Data is being loaded...");
- progressDialog.show();
- }
- @Override
- protected WeatherForecastInfo doInBackground(
- String... params) {
- return mapUtil.getForecastByCityName(DemoActivity.this, editText.getText().toString(), 2);
- }
- @Override
- protected void onPostExecute(WeatherForecastInfo result) {
- textView.setText(result.getCity().getName()+ " " + result.getCity().getCountry());
- list = result.getListItem().getWeather(); // Here Im getting NPE why???
- adapter = new ArrayAdapter<WeatherForecastInfo.ListItem.Weather>(DemoActivity.this, android.R.layout.simple_list_item_1, list);
- listView.setAdapter(adapter);
- progressDialog.dismiss();
- }
- }.execute(null, null, null);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement