I have a form in which user has to select his country from a spinner and later user has to select the city from another spinner. So is there anyway to where I can get all the countries in my spinner and the corresponding cities as well? Please help as it will be really impossible to make an array of all the countries and their cities. Thanks
Asked
Active
Viewed 6,211 times
1 Answers
9
If you want to get All Contries try as follows
ArrayList<String> list=new ArrayList<String>();
String[] locales = Locale.getISOCountries();
for (String countryCode : locales) {
Locale obj = new Locale("", countryCode);
System.out.println("Country Name = " + obj.getDisplayCountry());
list.add(obj.getDisplayCountry());
}
and set the list to adapter.
As of my knowledge To get cities you have to use webservices.
Hope this will helps you.

Nagaraju V
- 2,739
- 1
- 14
- 19
-
1Hey thanks this works to get the list of the countries but can we get the list of the cities based on the selected countries? – user3699550 Feb 27 '15 at 11:57
-
to get cities you have to use webservices. – Nagaraju V Feb 27 '15 at 11:58
-
how as this is my first project of this kind so I have no idea on this – user3699550 Feb 27 '15 at 12:00
-
Check this link it might help you [http://stackoverflow.com/questions/9760341/retrieve-a-list-of-countries-from-the-android-os], scroll down to @pathe.kiran answer. – M.Baraka Aug 25 '15 at 12:47