Do you want a simple code to get the name and the name of the city depended on the choice

I am new to android and java. I am developing a simple application that contains the country, state and city that are selected by the spinner. Now consider when I choose a country (India), then I need to get only the states of India. And then, choosing a state (Andhra Pradesh), then the cities of A.P. should be shown on the next counter. Can anyone suggest me some sample code.

early

0
source share
1 answer

you can add this logic (for two spinners) to your code:

public void onCreate() { .... Country[] mCountries = ... ; final Spinner spinner1 = ...; final Spinner spinner2 = ...; spinner1.setAdapter(new ArrayAdapter(mCountries); spinner1.setOnItemSelectedListener( new OnItemSelectedListener() { void onItemSelected(AdapterView<?> parent, View view, int position, long id) { Country country = (Country) parent.getAdapter().getItem(position); spinner2.setAdapter(new ArrayAdapter(country.getStates()); } void onNothingSelected(AdapterView<?> parent) { spinner2.setAdapter(null); } }); 

....}

+3
source

All Articles