I am getting a list that contains two lists of Time zones, of US and Canada from server. Id of Canada list is 1 and Us is 2.That lists contains string id and some other strings. I need that string id to be listed in spinner so that's why I am making new list that contains only strings that I need.
I put id's of countries in a switch statement and it should put list in spinner and it works fine. But it shows only the first two items from list.
for (int i = 0; i < list.size(); i++)
listCountryId.add(list.get(0).getTimeZoneModelList().get(i).getId());
so basically idea is that I loop through my list from server and because I always have only two lists in that list, in this case I loop through first list. That is why I hardcoded. When I debug I can see that my getTimeZoneModelList() contains full list but when I debug listCountryId() it contains only first two items.
this is my full code:
private void setUpSpinner() {
switch (model.getCountry().getCoutryId()) {
case 1:
for (int i = 0; i < list.size(); i++)
listCountryId.add(list.get(0).getTimeZoneModelList().get(i).getId());
ArrayAdapter<String> adapterMembers = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, listCountryId);
adapterMembers.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
binding.timezoneSpinner.setAdapter(adapterMembers);
Log.i(TAG, "lista idjeva: " + Arrays.toString(listCountryId.toArray()));
break;
case 2:
for (int i = 0; i < list.size(); i++) {
listCountryId.add(list.get(1).getTimeZoneModelList().get(i).getId());
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(
context, android.R.layout.simple_spinner_item, listCountryId);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
binding.timezoneSpinner.setAdapter(adapter);
Log.i(TAG, "lista idjeva: " + Arrays.toString(listCountryId.toArray()));
break;
}
}