All my spinners are connected with each other, they are not independent, I would like to show options in spinner2 and spinner3 based on the selection in spinner1 (I mean based on category chosen by user in spinner1)
In onCreate
I am populating data into Spinners, but in spinner2 and spinner3 I am getting data that belongs to CategoryB whereas they must populate with CategoryA data only.
So where is my mistake? Here is my JSON Parsing code:
categoryArrayList = new ArrayList<Category>();
cArrayList = new ArrayList<String>();
...................................
// Array Level 1 --- START
JSONArray jarray = jsono.getJSONArray("categories");
for (int i = 0; i < jarray.length(); i++) {
JSONObject object = jarray.getJSONObject(i);
Category language = new Category();
language.setName(object.getString("category_name"));
Log.d("category_name::-", object.getString("category_name"));
language.setTypeArrayList(typeArrayList);
categoryArrayList.add(language);
cArrayList.add(categoryArrayList.get(i).getName());
// Array Level 1 --- END
// Array Level 2 --- START
JSONArray jsarray = object.getJSONArray("types");
typeArrayList = new ArrayList<Type>();
tArrayList = new ArrayList<String>();
for (int j = 0; j < jsarray.length(); j++) {
JSONObject jjobject = jsarray.getJSONObject(j);
Type genre = new Type();
genre.setName(jjobject.getString("type_name"));
Log.d("type_name::-", jjobject.getString("type_name"));
genre.setServiceArrayList(serviceArrayList);
typeArrayList.add(genre);
tArrayList.add(typeArrayList.get(j).getName());
// Array Level 2 --- END
// Array Level 3 --- START
JSONArray jsonarray = jjobject.getJSONArray("services");
serviceArrayList = new ArrayList<Service>();
sArrayList = new ArrayList<String>();
for (int k = 0; k < jsonarray.length(); k++) {
JSONObject jjjobject = jsonarray.getJSONObject(k);
Service movie = new Service();
movie.setName(jjjobject.getString("service_name"));
Log.d("service_name::-", jjjobject.getString("service_name"));
serviceArrayList.add(movie);
sArrayList.add(serviceArrayList.get(k).getName());
// Array Level 3 --- END
}
}
}
return true;
}
And here is how i am populating Spinners:
spinner1.setAdapter(new ArrayAdapter<String>(CategoryActivity.this,
android.R.layout.simple_spinner_dropdown_item,
cArrayList));
spinner2.setAdapter(new ArrayAdapter<String>(CategoryActivity.this,
android.R.layout.simple_spinner_dropdown_item,
tArrayList));
spinner3.setAdapter(new ArrayAdapter<String>(CategoryActivity.this,
android.R.layout.simple_spinner_dropdown_item,
sArrayList));
spinner3
because it do not refer toCategory A
array – LeveyCatA TypeB ServiceA
in"category_name":"Category A",
– Leveyspinner2,spinner3
when your select"Category A"
– Leveygetarrtype_name
instead ofgetName
– Holytide