Populate a spinner based on the selection of another spinner. : I have to populate states depending on the selected country.I also have to capture the items selected in other spinners. But the listener methods are not getting called. 



....

countriesSpinner.setOnItemSelectedListener(this);

statesSpinner.setOnItemSelectedListener(this);

yearSpinner.setOnItemSelectedListener(this);

public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    // On selecting a spinner item
    
    switch(view.getId()){
        case R.id.countriesSpinner:
        {
            Log.i("selected country",selectedCountry);
            selectedCountry = parent.getItemAtPosition(position).toString();
            populateStates();
            ArrayAdapter stateAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, states);
            statesSpinner.setAdapter(stateAdapter);
        }
        break;

        case R.id.statesSpinner:
        {
            selectedState=parent.getItemAtPosition(position).toString();
        }
        break;

        case R.id.yearSpinner:
        {
            selectedYear=parent.getItemAtPosition(position).toString();
        }
    }



}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
