@Override public void onAttach(Activity activity) { super.onAttach(activity); Bundle args = activity.getIntent().getExtras(); forecastsArray = args.getString("Forecasts"); JSONArray forecasts; ForecastItem f = null; forecastItems = new ArrayList<ForecastItem>(); try { forecasts = new JSONArray(forecastsArray); int numForecasts = forecasts.length(); for (int i = 0; i < numForecasts; i++) { JSONObject forecast = forecasts.getJSONObject(i); f = new ForecastItem(); f.setDay(forecast.getString("Day")); f.setForecastText(forecast.getString("ForecastText")); f.setWeatherIcon(forecast.getInt("weather_icon")); forecastItems.add(f); } } catch (JSONException e) { e.printStackTrace(); } }
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; if (convertView == null) { convertView = getActivity().getLayoutInflater().inflate(R.layout.simple_list_item_with_icon, null); holder = new ViewHolder(); holder.title = (TextView) convertView.findViewById(R.id.title); holder.title.setTypeface(tfb); holder.text = (TextView) convertView.findViewById(R.id.text); holder.text.setTypeface(tf); holder.icon = (ImageView) convertView.findViewById(R.id.icon); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } ForecastItem o = items.get(position); holder.title.setText(o.getDay()); holder.text.setText(o.getForecastText()); holder.icon.setImageResource(o.getWeatherIcon()); return convertView; }