1 package de.example.exampletdd.fragment.specific;
3 import android.content.Context;
4 import android.view.LayoutInflater;
5 import android.view.View;
6 import android.view.ViewGroup;
7 import android.widget.ArrayAdapter;
8 import android.widget.ImageView;
9 import android.widget.TextView;
10 import de.example.exampletdd.R;
12 public class WeatherCurrentDataAdapter extends ArrayAdapter<Object> {
13 private static final int FIRST = 0;
14 private static final int SECOND = 1;
15 private static final int THIRD = 2;
16 private static final int FOURTH = 3;
17 private final int[] resources;
19 public WeatherCurrentDataAdapter(final Context context, final int[] resources) {
22 this.resources = resources;
27 public View getView(final int position, final View convertView, final ViewGroup parent) {
29 final View view = this.getWorkingView(position, convertView);
30 final int viewType = this.getItemViewType(position);
32 if (viewType == FIRST) {
34 final ViewFirstHolder viewHolder = this.getViewFirstHolder(view);
35 final WeatherCurrentDataEntryFirst entry = (WeatherCurrentDataEntryFirst) this
37 viewHolder.picture.setImageBitmap(entry.getPicture());
38 viewHolder.tempMax.setText(entry.getTempMax());
39 viewHolder.tempMin.setText(entry.getTempMin());
40 } else if (viewType == SECOND) {
41 final ViewSecondHolder viewHolder = this.getViewSecondHolder(view);
42 final WeatherCurrentDataEntrySecond entry = (WeatherCurrentDataEntrySecond) this
44 viewHolder.weatherDescription.setText(entry.getWeatherDescription());
45 } else if (viewType == THIRD) {
46 final ViewThirdHolder viewHolder = this.getViewThirdHolder(view);
47 final WeatherCurrentDataEntryThird entry = (WeatherCurrentDataEntryThird) this
49 viewHolder.humidityValue.setText(entry.getHumidityValue());
50 viewHolder.pressureValue.setText(entry.getPressureValue());
51 viewHolder.rainValue.setText(entry.getRainValue());
52 viewHolder.cloudsValue.setText(entry.getCloudsValue());
53 viewHolder.windValue.setText(entry.getWindValue());
54 } else if (viewType == FOURTH) {
55 final ViewFourthHolder viewHolder = this.getViewFourthHolder(view);
56 final WeatherCurrentDataEntryFourth entry = (WeatherCurrentDataEntryFourth) this
58 viewHolder.dayTemp.setText(entry.getDayTemp());
59 viewHolder.morningTemp.setText(entry.getEveTemp());
60 viewHolder.eveTemp.setText(entry.getEveTemp());
61 viewHolder.nightTemp.setText(entry.getNightTemp());
68 public int getItemViewType(final int position) {
73 } else if (position == 1) {
75 } else if (position == 2) {
77 } else if (position == 3) {
85 public int getViewTypeCount() {
89 private View getWorkingView(final int position, final View convertView) {
90 View workingView = null;
92 if (convertView == null) {
93 final int viewType = this.getItemViewType(position);
94 final Context context = this.getContext();
95 final LayoutInflater inflater = (LayoutInflater) context
96 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
98 workingView = inflater.inflate(this.resources[viewType], null);
100 workingView = convertView;
106 private ViewFirstHolder getViewFirstHolder(final View workingView) {
107 final Object tag = workingView.getTag();
108 ViewFirstHolder viewHolder = null;
110 if ((null == tag) || !(tag instanceof ViewFirstHolder)) {
111 viewHolder = new ViewFirstHolder();
113 viewHolder.picture = (ImageView) workingView
114 .findViewById(R.id.weather_current_data_picture);
115 viewHolder.tempMax = (TextView) workingView
116 .findViewById(R.id.weather_current_data_temp_max);
117 viewHolder.tempMin = (TextView) workingView
118 .findViewById(R.id.weather_current_data_temp_min);
120 workingView.setTag(viewHolder);
123 viewHolder = (ViewFirstHolder) tag;
129 private ViewSecondHolder getViewSecondHolder(final View workingView) {
130 final Object tag = workingView.getTag();
131 ViewSecondHolder viewHolder = null;
133 if ((null == tag) || !(tag instanceof ViewSecondHolder)) {
134 viewHolder = new ViewSecondHolder();
136 viewHolder.weatherDescription = (TextView) workingView
137 .findViewById(R.id.weather_current_data_description);
139 workingView.setTag(viewHolder);
142 viewHolder = (ViewSecondHolder) tag;
148 private ViewThirdHolder getViewThirdHolder(final View workingView) {
149 final Object tag = workingView.getTag();
150 ViewThirdHolder viewHolder = null;
152 if ((null == tag) || !(tag instanceof ViewThirdHolder)) {
153 viewHolder = new ViewThirdHolder();
155 viewHolder.humidityValue = (TextView) workingView
156 .findViewById(R.id.weather_current_data_humidity_value);
157 viewHolder.pressureValue = (TextView) workingView
158 .findViewById(R.id.weather_current_data_pressure_value);
159 viewHolder.rainValue = (TextView) workingView
160 .findViewById(R.id.weather_current_data_rain_value);
161 viewHolder.cloudsValue = (TextView) workingView
162 .findViewById(R.id.weather_current_data_clouds_value);
163 viewHolder.windValue = (TextView) workingView
164 .findViewById(R.id.weather_current_data_wind_value);
166 workingView.setTag(viewHolder);
169 viewHolder = (ViewThirdHolder) tag;
175 private ViewFourthHolder getViewFourthHolder(final View workingView) {
176 final Object tag = workingView.getTag();
177 ViewFourthHolder viewHolder = null;
179 if ((null == tag) || !(tag instanceof ViewFourthHolder)) {
180 viewHolder = new ViewFourthHolder();
182 viewHolder.morningTemp = (TextView) workingView
183 .findViewById(R.id.weather_morn_temperature);
184 viewHolder.dayTemp = (TextView) workingView.findViewById(R.id.weather_day_temperature);
185 viewHolder.eveTemp = (TextView) workingView.findViewById(R.id.weather_eve_temperature);
186 viewHolder.nightTemp = (TextView) workingView
187 .findViewById(R.id.weather_night_temperature);
189 workingView.setTag(viewHolder);
192 viewHolder = (ViewFourthHolder) tag;
199 private static class ViewFirstHolder {
200 public ImageView picture;
201 public TextView tempMax;
202 public TextView tempMin;
205 private static class ViewSecondHolder {
206 public TextView weatherDescription;
209 private static class ViewThirdHolder {
210 public TextView humidityValue;
211 public TextView pressureValue;
212 public TextView windValue;
213 public TextView rainValue;
214 public TextView cloudsValue;
217 private static class ViewFourthHolder {
218 private TextView morningTemp;
219 private TextView dayTemp;
220 private TextView eveTemp;
221 private TextView nightTemp;