Spinner spinner, spinner2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_check_box_tuts);
spinner = (Spinner)findViewById(R.id.spinner1);
spinner2 = (Spinner)findViewById(R.id.spinner2);
spinner.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> v, View arg1, int arg2,
long arg3) {
switch(v.getId()){
case R.id.spinner1:
if(spinner.getSelectedItemPosition() == 1){
//what goes here??
break;
}
}
}
Like my first spinner lists are countries : USA, JAPAN etc.. so after USA has been selected for example, my second spinner would able to get a list of USA’s state array..
I use my newbie logic to try to think this way : set the 2nd spinner to View.GONE, then if lets say USA is selected, show the spinner2 which it alone carry the states.. but if I have 60 countries, then I must have 60 spinner, that’s funny so help me 😀
Rather than creating a
Spinnerfor each country instance, keep the sameSpinner, and replace the data stored in it when a value is selected from your firstSpinnerwithArrayAdapter.createFromResource() and Spinner.setAdapter(). Here is an example using those two calls.
Rather than hiding your second
Spinnerbefore an option is selected in the first, consider having a default selection in the firstSpinner, and populating the second with the matching data. In your example, USA would be a good default selection.